R
rongtang
Unregistered / Unconfirmed
GUEST, unregistred user!
我用ADOQuery1.Spend ...... ADOQuery1.Post 把stringgrid1里的数据添加到access的数据表中,添加完数据,数据表中总会自动多出一空行来,第二次再添加,数据表中又是多一空行来。怎么处理呢?自我感觉:mdb数据库的表中,每用程序添加完数据,记录指针就自动下移到新的一行。于是每次添加完,数据表中就自动多了一行空行。代码顺便贴一下:ADOConnection1.Connected:=false;adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName)+'goodsMS.mdb;Persist Security Info=False';ADOConnection1.Connected:=true;adoquery1.Connection:=adoconnection1;adoquery1.Close;adoquery1.SQL.Clear;adoquery1.SQL.Add('select * from goods ');adoquery1.Open ;for i := 1 to stringgrid1.RowCount do begin try begin ADOquery1.append; ADOquery1.FieldByName('id').asstring:=stringgrid1.Cells [1,i]; ADOquery1.FieldByName('name').asstring:=stringgrid1.Cells [2,i]; ADOquery1.FieldByName('price').AsString:=stringgrid1.Cells [3,i]; ADOquery1.FieldByName('time').AsString:=stringgrid1.Cells [4,i]; ADOquery1.FieldByName('理由').AsString:=stringgrid1.Cells [5,i]; ADOquery1.Post; end; except showmessage('保存数据出错!'); end; end;ADOConnection1.Connected:=false;adoquery1.Close;