错误:Dataset not in edit or insert mode(50分)

  • 主题发起人 touchnet
  • 开始时间
T

touchnet

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾,小弟通过edit对dbgrid的cell进行赋值操作,编译通过,可运行时却出现这个错误。
我的table已经open了,为何会这样,请大家帮忙,谢谢!
 
好像思路错了,应该直接操作数据集 DBGRID.datasounce.dataset.fields[0].asstring;
可如何定位行,请高手指教,谢谢!
 
adotable1.open
adoTable1.First; //保持加入的记录以时间的降序排列
adoTable1.Insert; //添加一个空白记录
adoTable1.FieldByName('Cus_Serial').AsString:=Edit_Serial.Text;
adoTable1.FieldByName('Cus_Lock').AsString:=Edit_Hard.Text;
adoTable1.FieldByName('Cus_Key').AsString:=Edit_Key.Text;
adoTable1.FieldByName('Cus_Name').AsString:=Edit_CusName.Text;
adoTable1.FieldByName('Cus_Edition').AsString:=Edit_Edition.Text;
adoTable1.FieldByName('Cus_Addr').AsString:=Edit_CusAddr.Text;

adoTable1.FieldByName('Cus_Contract').AsString:=Comb_Contract.Text;
adoTable1.FieldByName('Cus_Operator').AsString:=Form2.Combo_Operator.text;


adoTable1.FieldByName('Cus_Ratifier').AsString:=Comb_Ratifier.Text;
adoTable1.FieldByName('Cus_Factor').AsString:=Comb_Factor.Text;
adoTable1.FieldByName('Cus_Date').AsString:=DateTimeToStr(Now);

adoTable1.FieldByName('Cus_Type').AsString:=Comb_Type.Text;
adoTable1.FieldByName('Cus_Phone').AsString:=Edit_Phone.Text;
adoTable1.FieldByName('Cus_Linkman').AsString:=Edit_Link.Text;
adoTable1.Post ;

table和adotable对于上面代码一样的,你换一下就行了

实在不行 你就写sql语句吧
 
to patriot:
谢谢你,不过你这个程序相当于遍历啊,我只想针对某个单元格赋值。
 
好像CellClick事件中可以取Column的值。但如果不通过这个事件能办到吗?
 
if adoTable1.Locate('Cus_Serial;Cus_Lock;Cus_Key',VarArrayOf(
[Edit_Serial.Text,Edit_Hard.Text,Edit_Key.Text]),[])//靠edit_serial,edit_hard,edit_key定位cus_serial,cus_lock,cus_key 位置。靠一字段定位去掉vararrayof[]直接写出定位参数如:edit_serial.text
then
begin
if adoTable1.CanModify then
begin
adoTable1.Edit;
adoTable1.FieldByName('Cus_Name').AsString:=Edit_CusName.Text;//修改的字段
adoTable1.FieldByName('Cus_Edition').AsString:=Edit_Edition.Text;//同上
adoTable1.FieldByName('Cus_Addr').AsString:=Edit_CusAddr.Text;//同上
adoTable1.Post;
end
else
ShowMessage('当前记录不能修改');
end
else
ShowMessage('没锁定要修改的记录,重新操作');

adotable和table一样,换一下就ok
 
上面第三,四行也为注释行!!!1
 

adoTable1.Post;
前添上一句
if adoTable1.state in [dsInsert,dsEdit] then
adoTable1.Edit;

 
to patriot: 请教一下
先申明一个类 type
mydb=class(tdbgrid);
procdure ....
........
table1.moveby(2);
mydb(dbgrid1).col:=2;
我这样定位可以吗?跟locate()有什么区别?
 
当对不知道位置的记录进行操作是用locate可以轻而易举的锁定到某个记录,然后对这个记录
部分字段进行操作。
你那样定位如果还有人对数据操作或数据记录是变化时,定位会混乱,而且很死板。呵呵你可别生气....
 
to patriot:
呵呵,再请教大虾,如果用dataset的话,怎样定位行,我想比较一下,谢谢!
 
顶部