全部代码:procedure TGjjDataDM.GetYhqqGjjgrxxData(const aUserID, aFileName, aYhbm, aGjdbm, aLmkh: string); var dataFile : TextFile; sline, s : string; cs, e025 : integer; a107, dqrq : TDate; dbg, a002, a008, a070 : string; begin if Trim(aLmkh) = '' then //如果卡号为空串、空格串,则查询结果为无数据 raise EDBException.Create(cntNoData, stNoData); cs := 0; SetLength(dbg, cntMaxLineLen); OpenDBConnection; aqGetYhqqGjjgrxxData.Close; aqGetYhqqGjjgrxxData.SQL.Clear; s := 'Select a002,a008,a011,a063,a033,a036,a038+a039 bngjje,a040,a044,a070,a034,a035,a063,a064,a107 from gzjbk where a079='''+ aLmkh +''''; aqGetYhqqGjjgrxxData.SQL.Add(s); AddDebugLog('sql: ' + s, m_Serial); aqGetYhqqGjjgrxxData.Open; if aqGetYhqqGjjgrxxData.IsEmpty then raise EDBException.Create(cntNoData, stNoData); try if FileExists(aFileName) then begin AssignFile(dataFile, aFileName); Append(dataFile); end else begin AssignFile(dataFile, aFileName); Rewrite(dataFile); end; try aqGetYhqqGjjgrxxData.First; repeat sline := ''; a002 := Trim(string(CheckIsNull(aqGetYhqqGjjgrxxData.FieldByName('a002').Value, //姓名 ' '))); sline := XStrToLenString(a002, 20); Writeln(dataFile, sline); //将数据行写入文本文件 aqGetYhqqGjjgrxxData.Next; Inc(cs); SetSafeResultStrDB(cs, m_Serial, stOperateDBNO + IntToStr(cs)); until aqGetYhqqGjjgrxxData.Eof; aqGetYhqqGjjgrxxData.Close; AddDebugLog(stOperateDBNO + IntToStr(cs), m_Serial); except raise EDBException.Create('第'+ inttostr(cs)+'条记录'+ stDBOperateErr); end; finally CloseFile(dataFile); end; end;