以下数据下载文本文件中:begintable表名1recordno=该表中记录条数fieldno=该表中记录列数
字段名1字段名2字段名3字段名4字段名5字段名6.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
endtable表名1.....请高手指教
字段名1字段名2字段名3字段名4字段名5字段名6.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
endtable表名1.....请高手指教
我就不用跟你说了!
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
(这个为数据库字段对应的数据)
begintable表名1recordno=该表中记录条数fieldno=该表中记录列数
(这是文本文件中的描述,指明了表数据的开始标志,表名,表中记录条数,该表中记录列数)endtable表名1(这个为一个表中数据的结束标志)
在文本文件中有好多这样的数据。也就是从好多表中到处的表数据
如下格式:begintable表名1recordno=该表中记录条数fieldno=该表中记录列数
字段名1字段名2字段名3字段名4字段名5字段名6.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
endtable表名1begintable表名1recordno=该表中记录条数fieldno=该表中记录列数
字段名1字段名2字段名3字段名4字段名5字段名6.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
endtable表名1begintable表名1recordno=该表中记录条数fieldno=该表中记录列数
字段名1字段名2字段名3字段名4字段名5字段名6.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
endtable表名1begintable表名1recordno=该表中记录条数fieldno=该表中记录列数
字段名1字段名2字段名3字段名4字段名5字段名6.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
值1值2值3值4值5值6值7.....
.........
endtable表名1
需要区分相应的表的开始标志和结束标志 ,然后读入数据库中的指定表中。
var
FileList, LineList : TStringList;
FileName, TableName, SQLStr, SQLValue: String;
i,j: Integer;
begin
FileName := ExtractFilePath (Application.ExeName) + 'yourFile.txt';
FileList := TStringList.Create;
LineList := TSTringList.Create; try
FileList.LoadFromFile(filename);
i := 0;
while i < FileList.Count do
begin
LineList.Clear;
ExtractStrings([''], [','], pchar(FileList.Strings[i]), LineList); // 在LineList中為一行分割後的数据
if LineList.Strings[0] = 'begintable' then
begin
showMessage(LineList.Text);
TableName := LineList.Strings[1];
inc(i);
LineList.Clear;
ExtractStrings([''], [','], pchar(FileList.Strings[i]), LineList);
showMessage(LineList.Text);
SQLStr := 'INSERT INTO ' + TableName + ' (';
for j := 0 To LineList.Count-1 do
begin
SQLStr := SQLStr + LineList.Strings[j] + ',';
end;
SQLStr := Copy(SQLStr,1,Length(SQLStr)-1) + ') VALUES ';
showMessage(SQLStr);
end
else if LineList.Strings[0] <> 'endtable' then
begin
SQLValue := SQLStr;
for j := 0 To LineList.Count-1 do
begin
SQLValue := SQLValue + QuotedStr(LineList.Strings[j]) + ','
end;
SQLValue := Copy(SQLValue,1,Length(SQLValue)-1) + ')'; //Insert SQL文
showMessage(SQLValue); with ADOQuery1 do //写入表中
begin
Close;
SQL.Clear;
SQL.Text := SQLValue;
ExecSQL;
end;
end;
inc(i);
end;{end while}
finally
LineList.Free;
FileList.Free;
end;
你自己删除掉showMessage...
with ADOQuery1 do //写入表中
begin
Close;
SQL.Clear;
SQL.Text := SQLValue;
ExecSQL;
end;
end;
这种写数据库是一条记录就执行一次写操作,如何进行批量写数据库呢?
就是如果我想有1万提条记录后,再提交控制权给数据库,让它完成写操作。这种怎么用ADO实现?