2,507
社区成员
发帖
与我相关
我的任务
分享

var i,k:Integer;
mh,sl,dw,ck,SQL,ID,ID1:string;
begin
k:=100;
DateTimetoString(ID1,'yymmddhhnnsszzz',now);
for i:=0 to ListBox1.Items.Count-1 do
begin
k:=k+1;
ID:=ID1+inttoStr(k);
S1:=ListBox1.Items[i];
S2:=ListBox2.Items[i];
S3:=ListBox3.Items[i];
S4:=ListBox4.Items[i];
SQL:='INSERT INTO zhongjian(mh,sl,dw,ck,ID) VALUES('+
#39+S1+#39+','+
#39+S2+#39+','+
#39+S3+#39+','+
#39+S4+#39+','+
#39+ID+#39+')';
adoquery1.sql.text:=SQL;
adoquery1.execsql;
end;
end;
上述代码仅代参考:
表字段中就有主键ID,ADOQuery连接数据库的方式,不一样,代码有异。
//保存到数据库
with adoquery1 do
begin
close;
sql.text:='insert into table1 values(mh,sl,dw,ck)';
sql.execsql;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
mh,sl,dw,ck:string;
begin
for i:=0 to ListBox1.Items.Count-1 do
begin
mh:=ListBox1.Items[i];
sl:=ListBox2.Items[i];
dw:=ListBox3.Items[i];
ck:=ListBox4.Items[i];
//保存到数据库 inset into zhongjian values(mh,sl,dw,ck);
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var
i:Integer;
begin
for i:=0 to ListBox1.Items.Count-1 do
ShowMessage(ListBox1.Items[ListBox1.ItemIndex]);{循环取出每条数据,保存到数据库中}
end;