DbGrid用法 delphi 我想手动向DBGRID里面添加记录 不合数据库挂钩如何实现?有帮忙的吗?就是通过代码增加记录! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那你就用 stringgrid吧~~DBGRID是数据感应组件,必须和数据库联接的~~ stringgrid设置row的数量,然后在cell中写数据StringGrid1.RowCount := 100;StringGrid1.Cells[1,1] := 'abc'; 以下是一个StringGrid1保存数据至数据库的例子: with StringGrid1 do for i:=1 to RowCount-1 do begin with dbfm5.stdqry do dbfm5.stdqry.Close; dbfm5.stdqry.SQL.Clear; dbfm5.stdqry.SQL.Add('select * from bmtg'); dbfm5.stdqry.Open; dbfm5.stdqry.Insert; dbfm5.stdqry.FieldByName('tg001').AsString:=trim(edit1.Text); dbfm5.stdqry.FieldByName('tg002').AsString:=cells[0,i]; dbfm5.stdqry.FieldByName('tg003').AsString:=cells[1,i]; dbfm5.stdqry.FieldByName('tg004').AsString:=cells[2,i]; dbfm5.stdqry.FieldByName('tg005').AsString:=cells[3,i]; dbfm5.stdqry.FieldByName('tg006').AsString:=cells[4,i]; dbfm5.stdqry.FieldByName('tg007').Value:=strtofloat(cells[5,i]); dbfm5.stdqry.FieldByName('tg008').Value:=strtofloat(cells[6,i]); dbfm5.stdqry.FieldByName('tg009').Value:=strtofloat(cells[7,i]); dbfm5.stdqry.FieldByName('tg010').Value:=strtofloat(cells[8,i]); dbfm5.stdqry.FieldByName('tg011').Value:=strtofloat(cells[9,i]); dbfm5.stdqry.FieldByName('tg012').Value:=strtofloat(cells[10,i]); dbfm5.stdqry.FieldByName('tg013').Value:=strtofloat(cells[11,i]); dbfm5.stdqry.FieldByName('tg014').Value:=strtofloat(cells[12,i]); dbfm5.stdqry.FieldByName('tg018').AsString:=cells[13,i]; dbfm5.stdqry.FieldByName('tg017').AsString:=cells[14,i]; dbfm5.bjcon.BeginTrans; try dbfm5.stdqry.Post; dbfm5.bjcon.CommitTrans; except dbfm5.bjcon.RollbackTrans; MessageDlg('数据保存失败,请检查输入的数据后重新执行或数据已经存在',mtError,[mbok],0); exit; end; end; clientdataset 创建内存表clientdataset.fieldsdefs.add('字段1',ftstring,10,false);clientdataset.fieldsdefs.add('字段2',ftstring,10,false);Clientdataset.CreateDataSet;datasoruce.dataset:=clientdataset;clientdataset.open;至于剩下的就是很普通的DBGRID操作差不多了 把字符串从变量复制到剪贴板如何做? 如何往TreeView1.Items[2].Data中存入和取出一个整数? 学习向服务器请求数据及接收数据,谁能在线指导一下.(愿意给) 关于状态对象与无状态对象 indy控件如何在装有wingate的代理服务器内进行mail发送和接收 字符串提取问题,在先等候 高分请教:如何将实际应用转化为类定义,以面向对象方式编程?哪里可以下载到以面向对象技术开发的范例程序(最好是数据库应用程序) UP有分,关于TreeView的问题 急!!如何显示系统给出的异常信息?在线等待! 怎么建立能有Execute的对话框? 求一路由表函数 有关操作TXT文件与数据库的问题
DBGRID是数据感应组件,必须和数据库联接的~~
StringGrid1.Cells[1,1] := 'abc';
with StringGrid1 do
for i:=1 to RowCount-1 do
begin
with dbfm5.stdqry do
dbfm5.stdqry.Close;
dbfm5.stdqry.SQL.Clear;
dbfm5.stdqry.SQL.Add('select * from bmtg');
dbfm5.stdqry.Open;
dbfm5.stdqry.Insert;
dbfm5.stdqry.FieldByName('tg001').AsString:=trim(edit1.Text);
dbfm5.stdqry.FieldByName('tg002').AsString:=cells[0,i];
dbfm5.stdqry.FieldByName('tg003').AsString:=cells[1,i];
dbfm5.stdqry.FieldByName('tg004').AsString:=cells[2,i];
dbfm5.stdqry.FieldByName('tg005').AsString:=cells[3,i];
dbfm5.stdqry.FieldByName('tg006').AsString:=cells[4,i];
dbfm5.stdqry.FieldByName('tg007').Value:=strtofloat(cells[5,i]);
dbfm5.stdqry.FieldByName('tg008').Value:=strtofloat(cells[6,i]);
dbfm5.stdqry.FieldByName('tg009').Value:=strtofloat(cells[7,i]);
dbfm5.stdqry.FieldByName('tg010').Value:=strtofloat(cells[8,i]);
dbfm5.stdqry.FieldByName('tg011').Value:=strtofloat(cells[9,i]);
dbfm5.stdqry.FieldByName('tg012').Value:=strtofloat(cells[10,i]);
dbfm5.stdqry.FieldByName('tg013').Value:=strtofloat(cells[11,i]);
dbfm5.stdqry.FieldByName('tg014').Value:=strtofloat(cells[12,i]);
dbfm5.stdqry.FieldByName('tg018').AsString:=cells[13,i];
dbfm5.stdqry.FieldByName('tg017').AsString:=cells[14,i];
dbfm5.bjcon.BeginTrans;
try
dbfm5.stdqry.Post;
dbfm5.bjcon.CommitTrans;
except
dbfm5.bjcon.RollbackTrans;
MessageDlg('数据保存失败,请检查输入的数据后重新执行或数据已经存在',mtError,[mbok],0);
exit;
end;
end;
clientdataset.fieldsdefs.add('字段2',ftstring,10,false);Clientdataset.CreateDataSet;datasoruce.dataset:=clientdataset;clientdataset.open;至于剩下的就是很普通的DBGRID操作差不多了