我的DBGrid中显示的是用Query查询的一些数据(一个表中) 我想在DBGrid中修改
然后点“提交” 可以存盘 ,该怎么写“提交”中的代码呢?************************
我用了一个UPdatesql控件 但总是改不了 这样写有什么错误?str:='update relation_select_course set grade='+inttostr(x1)+',again_grade='+inttostr(x2)+' where stud=:x1 and course_no=:x2';
with updatesql1 do
begin modifysql.Clear;
modifysql.Add(str);
parambyname('x1').asstring:=edit2.Text;
parambyname('x2').asstring:=combobox3.Text;
modifysql.BeginUpdate;
end;
showmessage('修改完毕!');
end; //if
然后点“提交” 可以存盘 ,该怎么写“提交”中的代码呢?************************
我用了一个UPdatesql控件 但总是改不了 这样写有什么错误?str:='update relation_select_course set grade='+inttostr(x1)+',again_grade='+inttostr(x2)+' where stud=:x1 and course_no=:x2';
with updatesql1 do
begin modifysql.Clear;
modifysql.Add(str);
parambyname('x1').asstring:=edit2.Text;
parambyname('x2').asstring:=combobox3.Text;
modifysql.BeginUpdate;
end;
showmessage('修改完毕!');
end; //if
程序运行时,Query产生的变动都存在Cached Buffer内,只胡执行Query.ApplyUpdates才会写入数据库内,每写入一笔到数据库时,就会调用Query的onUpdateRecord事件一次,这时在QueryUpdateRecord事件中写入如下代码:
Query.UpdateObject:=UpdateSQL1;
UpdateSQL1.SetParams(UpdateKind);
UpdateSQL1.ExecSQL(UpdateKind);
Query.UpdateObject:=UpdateSQL2;
UpdateSQL2.SetParams(UpdateKind);
UpdateSQL2.ExecSQL(UpdateKind);
UpdateAction:=uaApplied;
在写数据操作的代码为:
Query.ApplyUpdates;
Query.CommitUpdates;
取消修改操作为:
Query,CancelUpdates;
起码的modifysql.execsql呀 才可以把数据提交的