本人用以下方法将stringgrid中数据写入数据库,但这样如果做,需对stringgrid中每一条记录动态生成sql语句,然后再执行,这样效率慢,各位大哥有更好的方案吗?最好带个例子和代码procedure TxmzdForm.tlbtnSaveClick(Sender: TObject);
var
tempSql: TQuery;
i: integer;
Sqlstr: string;
begin
tempSql:=TQuery.Create(self);
try
tempsql.databaseName:=SystemDataModule.dbSystem.DatabaseName;
tempsql.SQL.Clear;
tempsql.SQL.Add('Delete from xmlszd where xmbh='+quotedstr(trim(edtxmbh.Text)));
tempsql.ExecSQL;
with stglszd do
begin
for i:=FixedRows to RowCount-FixedRows do
begin
tempsql.SQL.Clear;
sqlstr:='Insert into xmlszd (xmbh,zdxh,zdbh,zdmc,zdrq,bz) Values' +
'( '+quotedstr(cells[1,i])+','+quotedstr(cells[0,i])+','+
quotedstr(cells[3,i])+','+quotedstr(cells[4,i])+','+
quotedstr(cells[2,i])+','+quotedstr(cells[5,i])+')';
tempsql.SQL.Add(sqlstr);
tempsql.ExecSQL;
alreadyChange:=false;
end;
end;
finally
tempsql.Close;
tempsql.Free; end;
end;
var
tempSql: TQuery;
i: integer;
Sqlstr: string;
begin
tempSql:=TQuery.Create(self);
try
tempsql.databaseName:=SystemDataModule.dbSystem.DatabaseName;
tempsql.SQL.Clear;
tempsql.SQL.Add('Delete from xmlszd where xmbh='+quotedstr(trim(edtxmbh.Text)));
tempsql.ExecSQL;
with stglszd do
begin
for i:=FixedRows to RowCount-FixedRows do
begin
tempsql.SQL.Clear;
sqlstr:='Insert into xmlszd (xmbh,zdxh,zdbh,zdmc,zdrq,bz) Values' +
'( '+quotedstr(cells[1,i])+','+quotedstr(cells[0,i])+','+
quotedstr(cells[3,i])+','+quotedstr(cells[4,i])+','+
quotedstr(cells[2,i])+','+quotedstr(cells[5,i])+')';
tempsql.SQL.Add(sqlstr);
tempsql.ExecSQL;
alreadyChange:=false;
end;
end;
finally
tempsql.Close;
tempsql.Free; end;
end;
解决方案 »
- 新年 and 升星 = 新年好运
- 怎么读出ie的历史纪录阿
- 这段代码如何设事务(高手请看看)
- 在用DElPHI开发程序时,如数据库应用,会有很多的穸体和很大的代码,但都集中在一个可执行文件中了,有没有办法将代码
- Pdoxusrs.net文件有什么用,在运行delphi写的程序时经常提示它出错我用的是.dbf数据库
- 疯了,以下问题(TServerSocket 的线程阻塞方式,有代码)困扰我2天了!!100分,在线等待!!!
- 自制组件的一些迷茫请帮助解决。
- 这里还有没有会用CORBA的?有就请把这100分拿去啊~``(真解决问题将所有"可用分"附赠)
- 通过了国家高级程序员考试,主要学pb,delphi在上海薪金可拿多少?
- 这样的窗口怎样实现?
- 求救!!!Dll文件报错!!!
- 在程序里如何对word文档的编辑?
http://community.csdn.net/Expert/topic/3297/3297352.xml?temp=.9591791
然后
for i:=0 to Query.RecordCount-1 do begin
for j:=0 to Query.FieldCount-1 do begin
StringGrid1.Cells[i+1,j+1]:=Query.Fields.Fields[i].Value;
end;
end;
如果是分步式系统,不好用DBGrid,可以用带参数的SQL来插入这样比用SQL要快点