我想手动向DBGRID里面添加记录 不合数据库挂钩如何实现?有帮忙的吗?
就是通过代码增加记录!

解决方案 »

  1.   

    那你就用 stringgrid吧~~
    DBGRID是数据感应组件,必须和数据库联接的~~
      

  2.   

    stringgrid设置row的数量,然后在cell中写数据StringGrid1.RowCount := 100;
    StringGrid1.Cells[1,1] := 'abc';
      

  3.   

    以下是一个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;
      

  4.   

    clientdataset 创建内存表clientdataset.fieldsdefs.add('字段1',ftstring,10,false);
    clientdataset.fieldsdefs.add('字段2',ftstring,10,false);Clientdataset.CreateDataSet;datasoruce.dataset:=clientdataset;clientdataset.open;至于剩下的就是很普通的DBGRID操作差不多了