我们在 Matlab 中创建了一个注册表单,其中包含一些字段,例如姓名、年龄等。我们还使用 Sql Server(ODBC) 创建了一个数据库。现在我们可以读取 TextBox 的值并通过 get 属性将其显示在命令窗口中(它在按钮回调中)。我们必须在已经创建的数据库中插入该文本框值我们使用 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)