如何利用delphi向数据库中添加数据(在编写完了的界面中添加······)?
答案:2 悬赏:0
解决时间 2021-03-01 20:41
- 提问者网友:神仙爷爷
- 2021-03-01 16:43
如何利用delphi向数据库中添加数据(在编写完了的界面中添加······)?
最佳答案
- 二级知识专家网友:你好陌生人
- 2021-03-01 17:27
你的图上控件我看不清是什么! 如果只是向界面里输入 程序如下
var
Form1: TForm1;
i:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if i>0 then stringgrid1.RowCount:=stringgrid1.RowCount+1;
i:=i+1;
stringgrid1.Cells[0,i]:=inttostr(i) ;
stringgrid1.Cells[1,i]:=edit1.Text ;
stringgrid1.Cells[2,i]:=edit2.Text ;
stringgrid1.Cells[3,i]:=edit3.Text ;
stringgrid1.Cells[4,i]:=edit4.Text ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
stringgrid1.Cells[1,0]:='编号';
stringgrid1.Cells[2,0]:='用户';
stringgrid1.Cells[3,0]:='密码';
stringgrid1.Cells[4,0]:='备注';
end;
var
Form1: TForm1;
i:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if i>0 then stringgrid1.RowCount:=stringgrid1.RowCount+1;
i:=i+1;
stringgrid1.Cells[0,i]:=inttostr(i) ;
stringgrid1.Cells[1,i]:=edit1.Text ;
stringgrid1.Cells[2,i]:=edit2.Text ;
stringgrid1.Cells[3,i]:=edit3.Text ;
stringgrid1.Cells[4,i]:=edit4.Text ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
stringgrid1.Cells[1,0]:='编号';
stringgrid1.Cells[2,0]:='用户';
stringgrid1.Cells[3,0]:='密码';
stringgrid1.Cells[4,0]:='备注';
end;
全部回答
- 1楼网友:承载所有颓废
- 2021-03-01 17:39
你可以用DB控件,直接连接数据库
例如DBedit
把它的DataSource属性设置成你所查询出来表的数据集把DataField属性设置成你要关联的字段
在放几个Button 一个写成添加,一个写修改,一个写删除,一个写保存
添加中写入
查询出来表的数据集的名字.append
修改中写入
查询出来表的数据集的名字.edit
删除中
查询出来表的数据集的名字.delete
保存中写入
查询出来表的数据集的名字.post
这样基本就可以了
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯