最近在做一个股票分析系统,想把股票系统下载的F10 数据文件内股东人数数据读入SQL SERVER 表内
具体情况:
系统环境 :win7   SQL SERVER 2008 DELPHI股东人数数据已经导出,存在文本文件内(.TXT文件内)     如600100.TXT, 共有2000多个文本文件
现考虑用Delphi批量读入SQL SERVER,不知有无好的办法,  也可考虑用SQL SERVER 直接读入,请教各位,谢谢!

解决方案 »

  1.   

    文本是.TXT格式,想取出“股东户数”里的环比变化(%)里的数值,文本文件的名字是股票代码
    文本文件格式如下所示:
      ◆  大股东进出  ◆              ◇大智慧数据中心制作:更新时间:2014-05-06◇  前十大股东                      股东人数:319109        截止日期:2014-03-31
         名称                      持股数(万股)  占总股数  增减情况  股本性质
      ─────────────────────────────────────
      1. 中国平安保险(集团)股份有限   477907.70    50.20%      未变  流通A股,限
         公司-集团本级-自有资金                                      售流通股
      2. 中国平安人寿保险股份有限公    60732.80     6.38%      未变  流通A股
         司-自有资金
      3. 中国平安人寿保险股份有限公    22554.16     2.37%      未变  流通A股
         司-传统-普通保险产品
      4. 深圳中电投资股份有限公司      14858.78     1.56%      未变  流通A股
      5. 葛卫东                        10799.59     1.13%  -6094.16  流通A股
      6. 东方证券股份有限公司约定购     7510.00     0.79%      新进  流通A股
         回专用账户
      7. 中国民生银行-银华深证100指     4629.43     0.49%   -366.38  流通A股
         数分级证券投资基金
      8. 南方东英资产管理有限公司-      3873.62     0.41%   -112.82  流通A股
         南方富时中国A50ETF
      9. 中国工商银行-融通深证100指     3524.97     0.37%    -90.79  流通A股
         数证券投资基金
      10.中国银行-易方达深证100交易     3313.11     0.35%   -299.71  流通A股
         型开放式指数证券投资基金
         总    计                     609704.16    64.04%
      ─────────────────────────────────────  前十名无限售条件股东            股东人数:319109        截止日期:2014-03-31
         名称                      持股数(万股)  占流通股  增减情况  股本性质
      ─────────────────────────────────────
      1. 中国平安保险(集团)股份有限    83435.34    14.96%      未变  流通A股
         公司-集团本级-自有资金
      2. 中国平安人寿保险股份有限公    60732.80    10.89%      未变  流通A股
         司-自有资金
      3. 中国平安人寿保险股份有限公    22554.16     4.04%      未变  流通A股
         司-传统-普通保险产品
      4. 深圳中电投资股份有限公司      14858.78     2.66%      未变  流通A股
      5. 葛卫东                        10799.59     1.94%  -6094.17  流通A股
      6. 东方证券股份有限公司约定购     7510.00     1.35%      新进  流通A股
         回专用账户
      7. 中国民生银行-银华深证100指     4629.43     0.83%   -366.38  流通A股
         数分级证券投资基金
      8. 南方东英资产管理有限公司-      3873.62     0.69%   -112.82  流通A股
         南方富时中国A50ETF
      9. 中国工商银行-融通深证100指     3524.97     0.63%    -90.79  流通A股
         数证券投资基金
      10.中国银行-易方达深证100交易     3313.11     0.59%   -299.71  流通A股
         型开放式指数证券投资基金
         总    计                     215231.80    38.58%
      ─────────────────────────────────────  前十大股东                                             截止日期:2014-01-08
         名称                      持股数(万股)  占总股数  增减情况  股本性质
      ─────────────────────────────────────
      1. 中国平安保险(集团)股份有限   477907.70    50.20%      未变  流通A股,限
         公司-集团本级-自有资金                                      售流通股
      2. 中国平安人寿保险股份有限公    60732.80     6.38%      未变  流通A股
         司-自有资金
      3. 中国平安人寿保险股份有限公    22554.16     2.37%      未变  流通A股
         司-传统-普通保险产品
      4. 葛卫东                        16893.76     1.77%      未变  流通A股
      5. 深圳中电投资股份有限公司      14858.78     1.56%      未变  流通A股
      6. 中国民生银行-银华深证100指     4995.81     0.52%      未变  流通A股
         数分级证券投资基金
      7. 南方东英资产管理有限公司-      3986.44     0.42%      未变  流通A股
         南方富时中国A50ETF
      8. 中国工商银行-融通深证100指     3615.76     0.38%      未变  流通A股
         数证券投资基金
      9. 中国银行-易方达深证100交易     3612.82     0.38%      未变  流通A股
         型开放式指数证券投资基金
      10.兴亚集团控股有限公司           3500.00     0.37%      未变  流通A股
         总    计                     612658.03    64.35%
      ─────────────────────────────────────  前十大股东                      股东人数:298070        截止日期:2013-12-31
         名称                      持股数(万股)  占总股数  增减情况  股本性质
      ─────────────────────────────────────
      1. 中国平安保险(集团)股份有限   477907.70    50.20% 132338.00  流通A股,限
         公司-集团本级-自有资金                                      售流通股
      2. 中国平安人寿保险股份有限公    60732.80     6.38%      未变  流通A股
         司-自有资金
      3. 中国平安人寿保险股份有限公    22554.16     2.37%      未变  流通A股
         司-传统-普通保险产品
      4. 葛卫东                        16893.76     1.77%      未变  流通A股
      5. 深圳中电投资股份有限公司      14858.78     1.56%      未变  流通A股
      6. 中国民生银行-银华深证100指     4995.81     0.52%      未变  流通A股
         数分级证券投资基金
      7. 南方东英资产管理有限公司-      3986.44     0.42%      未变  流通A股
         南方富时中国A50ETF
      8. 中国工商银行-融通深证100指     3615.76     0.38%      未变  流通A股
         数证券投资基金
      9. 中国银行-易方达深证100交易     3612.82     0.38%      未变  流通A股
         型开放式指数证券投资基金
      10.兴亚集团控股有限公司           3500.00     0.37%      未变  流通A股
         总    计                     612658.03    64.35%
      ─────────────────────────────────────   ◆控股股东和实际控制人◆                                                    一、控股股东                                                              
      名    称: 中国平安保险(集团)股份有限公司
      法人代表: 马明哲
      注册资本: 791614.21万元
      成立日期: 1988-03-21
      经营业务: 投资保险企业;监督管理控股投资企业的各种国内、国际业务;开展保险
                资金运用业务;经批准开展国内、国际保险业务;经中国保险监督管理委
                员会及国家有关部门批准的其他业务。
      企业类型: 中外合资企业  二、实际控制人                                                            
      名    称: 无
      说    明: -
      ◆股东户数◆                                                                截止日期              股东户数        环比增减   环比变化(%)      人均持股
      ─────────────────────────────────────
      2014-03-31              319109            8774          2.83         17473
      2014-02-28              310335           12265          4.11         17967
      2013-12-31              298070            7016          2.41         18707
      2013-09-30              291054            9235          3.28         17071
      2013-06-30              281819           24834          9.66         17630
      2013-03-31              256985           23468         10.05         12084
      2013-03-01              233517          -29960        -11.37         13298
      2012-12-31              263477          -18020         -6.40         11786
      2012-09-30              281497           -1880         -0.66         11032
      2012-06-30              283377            7708          2.80         10958
      2012-03-31              275669            6090          2.26         11265
      2012-02-29              269579           -3367         -1.23         11519
      2011-12-31              272946           -1257         -0.46         11377
      2011-09-30              274203          -11239         -3.94         11325
      2011-06-30              285442          -55874        -16.37         10879
      2011-03-31              341316          -11339         -3.22          9098
      2010-12-31              352655           13111          3.86          8806
      2010-09-30              339544           44284         15.00          9146
      2010-06-30              295260           42840         16.97         10517
      2010-03-31              252420           21849          9.48         11584
      2009-12-31              230571          -29669        -11.40         12682
      2009-09-30              260240           16278          6.67         11235
      2009-06-30              243962           -4735         -1.90         11984
      2009-03-31              248697          -46519        -15.76         11197
      2008-12-31              295216           46357         18.63          9432
      2008-09-30              248859          -15847         -5.99          8607
      2008-06-30              264706           -4762         -1.77          8092
      2008-03-31              269468           19042          7.60          6520
      2007-12-31              250426           65926         35.73          6801
      2007-09-30              184500          -87655        -32.21          8402
      2007-06-30              272155          -23489         -7.95          5696
      2007-03-31              295644         -110589        -27.22          4767
      2006-12-31              406233         -104435        -20.45          3469
      2006-09-30              510668          -32836         -6.04          2760
      2006-06-30              543504          -59494         -9.87          2593
      2006-03-31              602998          -18314         -2.95          2337
      2005-12-31              621312           -9677         -1.53          2268
      2005-09-30              630989          -14712         -2.28          2234
      2005-06-30              645701          -13154         -2.00          2183
      2005-03-31              658855           -7341         -1.10          2139
      2004-12-31              666196           -5992         -0.89          2116
      2004-09-30              672188           -4442         -0.66          2095
      2004-06-30              676630            3607          0.54          2082
      2004-03-31              673023          -29438         -4.19          2093
      2003-12-31              702461           -1696         -0.24          2005
      2003-09-30              704157            8182          1.18          2000
      2003-06-30              695975           15555          2.29          2024
      2003-03-31              680420            3909          0.58          2070
      2002-12-31              676511           34282          5.34          2082
      2002-09-30              642229          -46327         -6.73          2193
      2002-06-30              688556          -90012        -11.56          2045
      2001-12-31              778568          -31432         -3.88          1809
      2000-12-31              810000           45875          6.00          1719
      2000-06-30              764125           58682          8.32          1401
      1999-12-31              705443         -209135        -22.87          1518
      1998-12-31              914578           -3753         -0.41          1171
      1998-06-30              918331           84860         10.18          1166
      1997-12-31              833471          502971        152.18          1285
      1996-12-31              330500          150500         83.61          2160
      1995-12-31              180000               -             -          1985
      ─────────────────────────────────────
      

  2.   

    procedure TFrmZDCDZP.BtnTransJianClick(Sender: TObject);
      var StrDate,StrZPH,StrJE,StrJD,fname1,fname2,s:string;
        f1,f2:textFile;
        ch:char;
        i,pp,j:integer;
        getdate:Boolean;
    begin
      if (leftStr(ComboBoxCPH.Text,4)<>'建行')then
      begin
        showmessage('出票行有误!');
        exit;
      end;
      AssignFile(f1,StxtFileName.Caption);
      Reset(f1);
        //readLn(f1);    //跳过一行
      while not eof(f1) do
      begin
        getDate:=True;
        StrDate:='';
        StrZPH:='';
        StrJD:='';
        StrJE:='';    readLn(f1, s);
        if s='' then
          Continue;
        StrDate:=copy(s,3,10);
        StrZPH:=copy(s,48,16); //1050443024598670
        StrJD:=copy(s,67,4);
        StrJE:=copy(copy(s,75,length(s)-1),1,pos('"',copy(s,75,length(s)-1))-1);
    {//   showmessage(s);   read(f1,ch);
       if (ch<>'"') then
       begin
        readln(f1);
        continue;
       end;
       while ch<>',' do        //日期
       begin
        if ((ch>='0') and (ch <= '9')) or (ch='-') then StrDate:=StrDate+ch;
        read(f1,ch);
       end;
       read(f1,ch);
       while ch<>',' do read(f1,ch);     //跳过时间
       read(f1,ch);
       while ch<>',' do read(f1,ch);     //跳过凭证种类
       read(f1,ch);
       while ch<>',' do        //凭证号
       begin
        if (ch>='0') and (ch<='9') then StrZPH:=StrZPH+ch;
        read(f1,ch);
       end;
       read(f1,ch);
       while ch<>',' do        //借贷
       begin
        if (ch<>'"') then StrJD:=StrJD+ch;
        read(f1,ch);
       end;
       read(f1,ch);
       while ch<>',' do        //金额
       begin
        if ((ch>='0') and (ch<='9')) or (ch='.') then StrJE:=StrJE+ch;
        read(f1,ch);
       end;   //readln(f1);
    }
       if strJD='借方' then
        with ADOquery4 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select top 1 * from 支票兑现');
          open;
          append;
          FieldByName('支票号').AsString:=Rightstr(StrZPH,8);
          FieldByName('金额').AsFloat:=StrToFloat(Trim(StrJE));
          FieldByName('承兑日期').AsDateTime:=StrToDate(StrDate);
          FieldByName('出票银行').AsString:=Trim(ComboBoxCPH.Text);
          Post;
        end;
    //   showmessage(StrDate+' '+StrZPH+'  '+StrJE);    ReadLn(f1);  end;  CloseFile(f1);
      PP:=Pos('未',StxtFileName.Caption);
      fname1:=StxtFileName.Caption;
      fname2:=Leftstr(fname1,pp-1)+'已'+Rightstr(fname1,length(fname1)-pp-1);
      CopyFile(PChar(fname1),PChar(fname2),False);
      DeleteFile(fname1);
      showmessage('转换成功!');
      ADOQuery1.Close;
      ADOQuery1.Open;
      SumUp;
    end;这是我读取支票明细的  你看看有没有用.     文件名如果是有序的.可以循环..
      

  3.   

    貌似auqfiudh的有参考价值,先谢谢
      

  4.   

    这是我导入股东人数等数据的函数 比较简单。你可以和通达信的F10数据比较着看
    procedure TfrmMain.ImportStockHolderCount(StockCode: string; Buf: pchar; BufLen: integer; FileProvider: integer);
    const
        SearchStringVsatsh = '历年人均持股情况';
        SearchStringGA = '【2.股东户数】';
    var
        p, p0, p1: pchar;
        str, SearchString: string;
        FormatSettings: TFormatSettings;
        SQL, SQLBASE: string;
        strDATE, strLTG, strGDRS, strRJCG: string;
        i: integer;    procedure CheckColumnWidth(ColumnWidth: integer);
        begin
            if (ColumnWidth <= 0) or (ColumnWidth > 20) then
                raise Exception.Create('Not Valid width!');
        end;var
        ColumnWidth: integer;begin
        FormatSettings.DateSeparator := '-';
        FormatSettings.LongDateFormat := 'yyyy-mm-dd';
        FormatSettings.ShortDateFormat := 'yyyy-mm-dd';    if FileProvider = Vsatsh then
            SearchString := SearchStringVsatsh
        else if FileProvider = GA then
            SearchString := SearchStringGA
        else
            ;
        SQLBASE := 'INSERT INTO STOCKOWNERCOUNT (CODE , DATE, LTG, GDRS, RJCG) VALUES '; //(:CODE ,  :DATE,  :LTG, :GDRS, :RJCG);';    if FileProvider = Vsatsh then
        begin
            //查找'历年人均持股情况'
            p0 := SearchBuf(Buf, BufLen, 0, Length(SearchString), SearchString, [SoDown]);
            if p0 = nil then
                exit;
            //跳过多余的行
            for I := 1 to 4 do
            begin
                p0 := SearchBuf(p0, BufLen - (p0 - buf), 0, 2, #$0D#$0A, [SoDown]);
                if p0 = nil then
                    exit;
            end;
            while True do
            begin
                try
                    //日期
                    p0 := p0 + 2;
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, 1, '│', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    strDate := trim(str);
                    StrToDate(strDate, FormatSettings); //检查str的合法性
                    //流通股
                    p0 := p1 + Length('│');
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, 1, '│', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    str := trim(str);
                    for i := Length(str) downto 1 do
                    begin
                        if not (str[i] in ['1'..'9', '0', '.']) then
                        begin
                            str := RightStr(str, Length(str) - i);
                            break;
                        end;
                    end;
                    strLTG := str;
                    strToFloat(strLTG); //检查str的合法性
                    //股东人数
                    p0 := p1 + Length('│');
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, 1, '│', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    strGDRS := trim(str);
                    StrToInt(strGDRS);
                    //人均持股
                    p0 := p1 + Length('│');
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, 1, '│', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    strRJCG := trim(str);
                    StrToFloat(strRJCG);                SQL := SQLBASE + '('
                        + '''' + StockCode + '''' + ', '
                        + '''' + strDate + '''' + ', '
                        + strLTG + ', '
                        + strGDRS + ', '
                        + strRJCG
                        + ');';
                    try
                        dmmain.ZConnStockF10.ExecuteDirect(SQL);
                    except
                    end;                p0 := SearchBuf(p0, BufLen - (p0 - buf), 0, 2, #$0D#$0A, [SoDown]);
                    if p0 = nil then
                        exit;
                except
                    Exit;
                end;
            end;
        end
        else if FileProvider = GA then
        begin
            p0 := buf;
            for I := 1 to 2 do
            begin
                p0 := SearchBuf(p0, BufLen, 0, Length(SearchString), SearchString, [SoDown]);
                if p0 = nil then
                    exit;
            end;
            for I := 1 to 4 do
            begin
                p0 := SearchBuf(p0, BufLen - (p0 - buf), 0, 2, #$0D#$0A, [SoDown]);
                if p0 = nil then
                    exit;
            end;
            while True do
            begin
                try
                    //日期
                    p0 := p0 + 2 + Length('|');
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, Length('|'), '|', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    strDate := trim(str);
                    StrToDate(strDate, FormatSettings); //检查str的合法性
                    //股东户数
                    p0 := p1 + Length('|');
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, Length('|'), '|', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    strGDRS := trim(str);
                    StrToInt(strGDRS);
                    //人均持股
                    p0 := p1 + Length('|');
                    p1 := SearchBuf(p0, BufLen - (p0 - buf), 0, Length('|'), '|', [SoDown]);
                    ColumnWidth := p1 - p0;
                    CheckColumnWidth(ColumnWidth);
                    SetLength(str, ColumnWidth);
                    Move(p0[0], str[1], ColumnWidth);
                    strRJCG := trim(str);
                    StrToFloat(strRJCG);
                    //流通股
                    strLTG := IntToStr(RoundEx(StrToInt(strGDRS) * StrToFloat(strRJCG) / 10000));                SQL := SQLBASE + '('
                        + '''' + StockCode + '''' + ', '
                        + '''' + strDate + '''' + ', '
                        + strLTG + ', '
                        + strGDRS + ', '
                        + strRJCG
                        + ');';
                    try
                        dmmain.ZConnStockF10.ExecuteDirect(SQL);
                    except
                    end;
                    for I := 1 to 2 do
                    begin
                        p0 := SearchBuf(p0, BufLen - (p0 - buf), 0, 2, #$0D#$0A, [SoDown]);
                        if p0 = nil then
                            exit;
                    end;
                except
                    Exit;
                end;
            end;
        end
        else
        begin
        end;
    end;
      

  5.   

    先谢谢,我好久没有DELPHI了,不知各位现在在用哪个版本了?