我将一个文本数据文件加载到数据库目标表中是没有问题的,下面是我的程序
procedure TDataLoadFrm.DataLoad(strFileName,strTableName,strDepart:string);
var
i,j: integer;
TextFileVar: TextFile;
temp: string;
StrLen, num: Integer;
DataSet:TDataSet;
begin
if strFileName = '' then exit;
AssignFile(TextFileVar, strFileName);
Reset(TextFileVar);
Readln(TextFileVar,temp); //表名信息
Readln(TextFileVar, temp); //字段信息
with adoQueryLoad do
begin
close;
sql.Clear;
sql.Add('select * from '+strTableName);
open;
end;
try
begin
while not SeekEof(TextFileVar) do
begin
Readln(TextFileVar, temp);
//得到标记数
StrLen := Length(trim(temp));
Num := 0;
for i := 1 to StrLen do
if Copy(temp, i, 1) = strDepart then
Num := Num + 1; //数据表列数
if pos(strDepart, temp) > 0 then
begin
adoQueryLoad.Append;
for j :=0 to Num-1 do
begin
adoQueryLoad.Fields[j].AsString := copy(Temp, 1, pos(strDepart, temp) - 1);
temp := copy(temp, pos(strDepart, temp) + 1, length(temp) - pos(strDepart, temp));
end;
end
else
adoQueryLoad.Fields[j].AsString := copy(Temp, 1, length(temp));
end;
//(????我现在要在adoQueryLoad.Post之前取得被插入的纪录集,并在dbgrid中显示出来)
adoQueryLoad.Post; showmessage('加载成功!');
end
except
showmessage('加载失败!');
end;
end;我用的是oracle数据库,如果要实现的必须先在库中新建临时表吗?
procedure TDataLoadFrm.DataLoad(strFileName,strTableName,strDepart:string);
var
i,j: integer;
TextFileVar: TextFile;
temp: string;
StrLen, num: Integer;
DataSet:TDataSet;
begin
if strFileName = '' then exit;
AssignFile(TextFileVar, strFileName);
Reset(TextFileVar);
Readln(TextFileVar,temp); //表名信息
Readln(TextFileVar, temp); //字段信息
with adoQueryLoad do
begin
close;
sql.Clear;
sql.Add('select * from '+strTableName);
open;
end;
try
begin
while not SeekEof(TextFileVar) do
begin
Readln(TextFileVar, temp);
//得到标记数
StrLen := Length(trim(temp));
Num := 0;
for i := 1 to StrLen do
if Copy(temp, i, 1) = strDepart then
Num := Num + 1; //数据表列数
if pos(strDepart, temp) > 0 then
begin
adoQueryLoad.Append;
for j :=0 to Num-1 do
begin
adoQueryLoad.Fields[j].AsString := copy(Temp, 1, pos(strDepart, temp) - 1);
temp := copy(temp, pos(strDepart, temp) + 1, length(temp) - pos(strDepart, temp));
end;
end
else
adoQueryLoad.Fields[j].AsString := copy(Temp, 1, length(temp));
end;
//(????我现在要在adoQueryLoad.Post之前取得被插入的纪录集,并在dbgrid中显示出来)
adoQueryLoad.Post; showmessage('加载成功!');
end
except
showmessage('加载失败!');
end;
end;我用的是oracle数据库,如果要实现的必须先在库中新建临时表吗?
解决方案 »
- 如何实现自动填表呢?
- Delphi调用DLL的问题
- 关于用delphi7开发ePass 1000接口函数的问题
- 请教,多线程问题!
- delphi开发active控件,如何公布一个接口类型的属性供vb使用?
- 你们说这种说法对吗?发到串口上的数据不接受难道还有影响?
- Delphi彻底研究.看过这书的给些意见
- 关于cxDBLookupComboBox的使用方法!!!!
- 如何将string类型转换成pchar类型?
- 为何Fastnet的FTP控件不能传大文件????
- 如何制作一个IP地址输入框啊,并且能检测输入的正确性?
- 怎么判断XP里自带的防火墙功能有没启用,如果启用了怎么关了它(声明,我不是在做本马)。
我找到delphi里也可以创建recordset对象,但当我设置她的cursorLacation时老是类型不匹配:
var
rstFans:_Recordset;
begin
rstFans.CursorLocation:=clUseClient;//????
adUseServer = $00000002;
adUseClient = $00000003;
adUseClientBatch = $00000003;试一试直接付值:rstFans.CursorLocation:=$00000003;
我想问一下:delphi里的recordset对象是不是和vb中的一样呢?都是微软的东东?