各位大虾帮帮忙 急急!200分(100)

  • 主题发起人 主题发起人 wisdomphg
  • 开始时间 开始时间
W

wisdomphg

Unregistered / Unconfirmed
GUEST, unregistred user!
从degrid1选一个或多个记录,添加到degrid2中,degrid1中选中的数据要删除去,这个数据在degrid2中不刷新就能显示,以下是富翁朋友给的我不知道代码问题出在那,运行dbgrid1--->dbgrid2会报错.属性:query1 query2dbgrid1. dbgrid2ClientDataSet1 ClientDataSet2 DataSetProvider1datasource1.dataset :=ClientDataSet1;dbgrid1.datasource := datasource1;datasource2.dataset :=ClientDataSet2;dbgrid2.datasource := datasource2;--------------------DBGrid1取数据代码query1.close;query1.sql.text:=_____________;query1.open;DataSetProvider1.DataSet:=query1;ClientDataSet1.close;ClientDataSet1.Data:= DataSetProvider1.Data;--------------------------------------------------dbgrid1-->dbgrid2代码:var I:Integer;begin if ClientDataSet1.RecordCount<=0 then exit; ClientDataSet2.Append; For i:=0 to ClientDataSet1.Fields.Count-1 do ClientDataSet2.Fields.Value:=ClientDataSet1.Fields.Value; ClientDataSet2.Post; ClientDataSet1.Delete;end;
 
错误内容?请确保Clientdataset1和Clientdataset2已经打开,且2个Clientdataset的字段相同。
 
是啊,两个ClientDataSet结构,字段相同吗?
 
znxia你好连接的两个表的字段都一样;你说的"打开"是不是ClientDataSet1.active=true;
 
znxia你好,query用adoquery代替能用吗?
 
大部分对,少了点东西!For i:=0 to ClientDataSet1.Fields.Count-1 dobegin Application.ProcessMessage; ClientDataSet2.Append; ClientDataSet2.Edit; ClientDataSet2.Fields.Value:=ClientDataSet1.Fields.Value; ClientDataSet2.Post;end;
 
query可以用adoquery代替,也可以用table/adotable代替。执行ClientDataSet1.Data:= DataSetProvider1.Data;,如果没异常,那ClientDataSet1就已经active(即open)了。------------------------楼上代码: ClientDataSet2.Append; ClientDataSet2.Edit;估计没多少人理解为什么Append后还要Edit,我也没理解。
 
znxia你好ClientDataSet1.Data:= DataSetProvider1.Data有通过执行dbgrid1-->dbgrid2代码:时有错误提示为ClientDataSet2:cannot perform this operation on a closed dataset
 
数据集没打开~`你看看ClientDataSet1,ClientDataSet2 这两个数据集打开没~~
 
znxiaClientDataSet1与adoquery没连上,我把ClientDataSet1.active=true提示:ClientDataSet1:missing data provider or data packet
 
应该是ClientDataSet没有配置应用程序服务器端 (DCOMConnection等)
 
ClientDataSet2:cannot perform this operation on a closed dataset 你打开了ClientDataSet2没有?----------------DBGrid2取数据代码query2.close;query2.sql.text:=_____________;query2.open;DataSetProvider1.DataSet:=query2;ClientDataSet2.close;ClientDataSet2.Data:= DataSetProvider1.Data;
 
znxia下面代码没有问题,因为我运行后,在dbgrid1里面有出现数据.procedure TForm1.Button2Click(Sender: TObject);beginadoquery1.close;adoquery1.sql.text:='select * from dep';adoquery1.open;DataSetProvider1.DataSet:=adoquery1;ClientDataSet1.close;ClientDataSet1.Data:= DataSetProvider1.Data;end;真正有问题的是下面代码,报错的提示:ClientDataSet1:missing data provider or data packetprocedure TForm1.Button1Click(Sender: TObject);var I:Integer;begin begin if ClientDataSet1.RecordCount<=0 then exit; Application.ProcessMessages ; ClientDataSet2.Append; For i:=0 to ClientDataSet1.Fields.Count-1 do ClientDataSet2.Fields.Value:=ClientDataSet1.Fields.Value; ClientDataSet2.Post; ClientDataSet1.Delete;end;end;
 
znxia刚才发提示写错了.下面代码没有问题,因为我运行后,在dbgrid1里面有出现数据.procedure TForm1.Button2Click(Sender: TObject);beginadoquery1.close;adoquery1.sql.text:='select * from dep';adoquery1.open;DataSetProvider1.DataSet:=adoquery1;ClientDataSet1.close;ClientDataSet1.Data:= DataSetProvider1.Data;end;真正有问题的是以下面代码,报错的提示:ClientDataSet2:cannot perform this operation on a closed dataset procedure TForm1.Button1Click(Sender: TObject);var I:Integer;begin begin if ClientDataSet1.RecordCount<=0 then exit; Application.ProcessMessages ; ClientDataSet2.Append; For i:=0 to ClientDataSet1.Fields.Count-1 do ClientDataSet2.Fields.Value:=ClientDataSet1.Fields.Value; ClientDataSet2.Post; ClientDataSet1.Delete;end;end;
 
我的意思是dbgrid1获取了数据,dbgrid2也要编写类似的数据来获取数据,以确保clientdataset2和clientdataset1一样,处于打开状态。procedure TForm1.Button1Click(Sender: TObject);var I:Integer;begin if not Clientdataset1.active then begin showmessage('Clientdataset1没打开'); exit; end; if not Clientdataset2.active then begin showmessage('Clientdataset2没打开'); exit; end; if ClientDataSet1.RecordCount<=0 then exit; Application.ProcessMessages ; ClientDataSet2.Append; For i:=0 to ClientDataSet1.Fields.Count-1 do ClientDataSet2.Fields.Value:=ClientDataSet1.Fields.Value; ClientDataSet2.Post; ClientDataSet1.Delete;end;
 
znxia ClientDataSet2里的数据怎么保存?
 
ClientDataSet2.first;while not ClientDataSet2.eof dobegin //通过ADO把当前数据insert或者update到数据库。 ClientDataSet2.next;end;
 
znxia你好以下代码对吗?谢谢指教,我是一个初学者.procedure TForm1.Button1Click(Sender: TObject);beginwhile not ClientDataSet1.Eof dobegin ClientDataSet2.First ; adoquery2.Close; adoquery2.SQL.Clear; adoquery2.SQL.Add('INSERT INTO dep1 (GONGX_NO, DEP_NAME, relid) values ('''+ClientDataSet1.Fields[0].Value+''','''+ClientDataSet1.Fields[1].Value+''','''+ClientDataSet1.Fields[2].Value+'''); adoquery2.Open ; ClientDataSet2.Next ;
 
procedure TForm1.Button1Click(Sender: TObject);begin ClientDataSet2.First ;//放到while之前while not ClientDataSet1.Eof do //应该是 ClientDataSet2.Eofbegin adoquery2.Close; adoquery2.SQL.Clear; adoquery2.SQL.Add('INSERT INTO dep1 (GONGX_NO, DEP_NAME, relid) values ('''+ClientDataSet2.Fields[0].Value+''','''+ClientDataSet2.Fields[1].Value+''','''+ClientDataSet2.Fields[2].Value+'''); //应该从ClientDataSet2取数据 adoquery2.Open ; // adoquery2.ExecSQL,不是open ClientDataSet2.Next ;end;建议将adoquery2更改为ADOCommand1.CommandText:= ...ADOCommand1.Execute;因为adoquery2执行insert/Update之后,就不可以再执行select语句,以后方式用ado执行更新、插入,请使用ADOCommand1我不嫌你是否为初学者,给分就可以。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
748
import
I
后退
顶部