我将一个文本数据文件加载到数据库目标表中是没有问题的,下面是我的程序
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数据库,如果要实现的必须先在库中新建临时表吗?

解决方案 »

  1.   

    你可以尝试用clientdataset这个控件,读他的DATEL属性就可以提取修改或添加的数据
      

  2.   

    clientdataset这个控件我没用过,但我一直在想,delphi难道不能象vb那样创建动态的临时数据集吗?vb里的recordset对象可以实现的
    我找到delphi里也可以创建recordset对象,但当我设置她的cursorLacation时老是类型不匹配:
    var
        rstFans:_Recordset;
     begin
        rstFans.CursorLocation:=clUseClient;//????

      

  3.   

    adUseNone = $00000001;
      adUseServer = $00000002;
      adUseClient = $00000003;
      adUseClientBatch = $00000003;试一试直接付值:rstFans.CursorLocation:=$00000003;
      

  4.   

    还是没用阿
    我想问一下:delphi里的recordset对象是不是和vb中的一样呢?都是微软的东东?