TXT格式为:
----------------------------------------
aaa  bbb  ccc  dddd
bbaee  aasdf  xzcv  adsf
df    adf  asdf   (第二个数据没有)
dfbvbbb  a32a  ff     (第四个数据没有)
----------------------------------------
注:中间中以TAB分隔,如果没有数据就为两个TAB

解决方案 »

  1.   

    笨点的方法,读出一行,然后按TAB键(#09) 来把一行分为四部分,在Insert就行了。
      

  2.   

    在程序中用循环,如2楼
    或者你可以用sql server的bcp或者dts直接就完成了阿,如果连续的tab会引起误差,你可以用stringreplace将tabtab用tabAtab代替,倒入后将值为A的update为null(你可以不用A,举例而已)
      

  3.   

    能不能详细说明一下bcp与dts怎么用呀?
      

  4.   

    我刚在大富翁写了一段DTS的代码,你可以去看看。
      

  5.   

    我有一段代码是取出由特殊字符分隔的字符串 如下:
    function  Getchar(var str:string ):Tstrings;
         var
          num :Tstrings;
          begin
          str:=trim(str);
          num:=tstringlist.Create;
          while pos(' ',str)>0 do
            begin
            trim(str);
            num.Add(copy(str,1,pos(' ',str)));
            delete(str,1,pos(' ',str));
            pos(' ',str);
            end ;
            num.Add(str);
           Result:=num;
          end;
      

  6.   

    可以用一个Sql Server的一个内部存储过程读入TEXT文档内容,具体这个存储过程叫什么名字我忘了,但是我曾用过这种方法交换数据。
      

  7.   

    大家顺便看看我的问题,同出一辙http://expert.csdn.net/Expert/topic/2003/2003503.xml?temp=.6684381
      

  8.   

    我的处理是先把整个文本中要用到的数据读入一个二维数组(缺数据的用Null表示)
    我写过一个处理CSV文件的类,贴出来给大家看一看,请指教:
    Unit CSVFileAccess;interfaceuses
        SysUtils, Windows,Classes,ComCtrls;type
        TCsvAccess=class(TObject)
        private
            CsvText:TStringList;
            RowCount:Integer;
            ColCount:Integer;
            CsvArray:Array of Array of String;
    public
            constructor Create;overload;
    destructor Destroy;override;
    procedure AssignFile(FileName:String);  //文件关联
            procedure FormatAllValue;               //文件"格式化",把文件内容存到一个二维数组内
    function GetColCount:Integer;           //得到列数
    function GetRowCount:Integer;           //得到行数
    function GetHeaderAt(Index:Integer):String;     //得到某列标题
    function GetContentAt(Row,Col:Integer):String;  //得到某行某列的值
    end;implementationConstructor TCsvAccess.Create;
    begin
    CsvText:=TstringList.Create;
    end;destructor TCsvAccess.Destroy;
    begin
    CsvText.Free;
    end;procedure TCsvAccess.AssignFile(FileName:String);
    begin
        CsvText.LoadFromFile(FileName);
        FormatAllValue;
    end;procedure TCsvAccess.FormatAllValue;
    var
        Row,Col:Integer;
        PosCount:Integer;
        CsvStr:String;
    begin
    RowCount:=GetRowCount;
        ColCount:=GetColCount;
        SetLength(CsvArray,RowCount,ColCount);
        for Row:=0 to RowCount-1 do
        begin
            CsvStr:=CsvText.Strings[Row];
            for Col:=0 to ColCount-1 do
            begin
                if Pos(',',CsvStr)<>0 then
    begin
    PosCount:=Pos(',',CsvStr);
                    CsvArray[Row,Col]:=Copy(CsvStr,1,PosCount-1);
       CsvStr:=Copy(CsvStr,PosCount+1,Length(CsvStr)-PosCount);
         end
                else
                begin
             CsvArray[Row,Col]:=CsvStr;
                end;
            end;
        end;
    end;function TCsvAccess.GetColCount:Integer;
    var
    Count,PosCount:Integer;
    CsvStr:String;
    begin
    Count:=0;
    CsvStr:=CsvText.Strings[0];
    while Pos(',',CsvStr)<>0 do
    begin
    PosCount:=Pos(',',CsvStr);
       Count:=Count+1;
         CsvStr:=Copy(CsvStr,PosCount+1,Length(CsvStr)-PosCount);
        end;
        Count:=Count+1;
    Result:=Count;
    end;function TCsvAccess.GetRowCount:Integer;
    begin
    Result:=CsvText.Count;
    end;function TCsvAccess.GetHeaderAt(Index:Integer):String;
    begin
        if Index<ColCount then
        begin
         Result:=CsvArray[0,Index];
        end;
    end;function TCsvAccess.GetContentAt(Row,Col:Integer):String;
    begin
        if (Row<RowCount) and (Col<ColCount) then
        begin
            Result:=CsvArray[Row,Col];
        end;
    end;end.
      

  9.   

    注:CSV文件是以逗号分隔的文本文件,把逗号换成tab符即可,缺的数据相应数组元素值为空
      

  10.   

    EXEC master..xp_cmdshell 'bcp DATABASENAME.dbo.TABLENAME in d:\temp1.txt -c -q -S"SERVERNAME" -U"sa" -P""'
      

  11.   

    可以利用SQL SERVER自己的导入功能了
    这样比较方便