//ADOConnection1 为 TADOConnection; //只是给你一个方法,具体的自己改一下就行了。 procedure TForm1.Button1Click(Sender: TObject); var i:Integer; C:Integer; const SQL='INSERT INTO Table1 (StudentName) VALUES %s'; begin C:=ListBox1.Items.Count - 1; ADOConnection1.BeginTrans; try for i=0 to C do begin ADOConnection1.Execute(Format(SQL,[ListBox1.Items[i]]); end; ADOConnection1.CommitTrans; ShowMessage('OK'); except ShowMessage('Error'); ADOConnection1.RollbackTrans; end; end;
Var I:integer;For i:=0 to Listbox1.count-1 do begin Adoquery1.insert; Adoquery1.fieldbyname('字段名').asstring:=listbox1.item[i]; Adoquery1.post; end;其中Adoquery1为你的数据集
用这个可以把所有的Item取出来
ListBox1.Items.DelimitedText;
//只是给你一个方法,具体的自己改一下就行了。
procedure TForm1.Button1Click(Sender: TObject);
var
i:Integer;
C:Integer;
const
SQL='INSERT INTO Table1 (StudentName) VALUES %s';
begin
C:=ListBox1.Items.Count - 1;
ADOConnection1.BeginTrans;
try
for i=0 to C do
begin
ADOConnection1.Execute(Format(SQL,[ListBox1.Items[i]]);
end;
ADOConnection1.CommitTrans;
ShowMessage('OK');
except
ShowMessage('Error');
ADOConnection1.RollbackTrans;
end;
end;
begin
Adoquery1.insert;
Adoquery1.fieldbyname('字段名').asstring:=listbox1.item[i];
Adoquery1.post;
end;其中Adoquery1为你的数据集