0

名前、年齢などのフィールドを含む登録フォームを Matlab で作成しました。また、Sql Server(ODBC) を使用してデータベースを作成しました。これで、TextBox の値を読み取り、プロパティを取得してコマンド ウィンドウに表示できます (プッシュボタンのコールバックにあります)。すでに作成されているデータベースにそのテキストボックスの値を挿入する必要があります。 fastinsert コマンドを使用します。ただし、手動で(クエリを使用して)値を追加するだけですが、テキストボックスを介して追加したいと考えています。プッシュ ボタン コールバックのコードはこちらです。

conn = database('Addface_DSN','sa','123 ');

if(isempty(conn.message))

     disp('database connected')

 else
     disp('cannot connected')

     disp(conn.message);

     return
end

setdbprefs('DataReturnFormat','numeric')

exdata = {'2','Shalu','22','female'};

fastinsert(conn, 'Faces_Details', {'Id' 'Name' 'Age' 'Gender' },exdata)

commit(conn)

close(conn);

name = get(handles.edit1, 'string'); % we dont want this, But just add to chek. we want this name in database.

disp(name)

age = get(handles.edit2, 'string'); 

disp(age)
4

1 に答える 1

0

この解決策を試してください ほとんどの解決策はあなたのコードだけです

conn = database('Addface_DSN','sa','123 ');

if(isempty(conn.message))

     disp('database connected')

 else
     disp('cannot connected')

     disp(conn.message);

     return
end

setdbprefs('DataReturnFormat','numeric')

// Here is the difference

// Taking test_age as 'int' 
test_name=get(handles.edit1, 'string'); 
test_age= get(handles.edit2, 'string');
//Convert to int and then insert
test_age=str2num(test_age);
exdata2={'3',test_name,test_age,'Male'};

exdata = {'2','Shalu','22','female'};

//Here you insert the data.
fastinsert(conn, 'Faces_Details', {'Id' 'Name' 'Age' 'Gender' },exdata2)

commit(conn)

close(conn);

name = get(handles.edit1, 'string'); % we dont want this, But just add to chek. we want   this name in database.

disp(name)

age = get(handles.edit2, 'string'); 

disp(age)
于 2014-07-21T06:00:07.123 に答える