FireDAC FDBatchMoveTextReader在运行时更改字段数据类型

时间:2015-09-17 09:54:10

标签: delphi firedac

我正在尝试使用FDBatchMoveTextReader解析不同的文本文件。我仅使用GuessFormat程序来确定字段数。因此,我将AnalyzeSample设置为10行。我试图在GuessFormat运行后手动将每个字段的数据类型设置为字符串。当我运行执行时,我收到错误说

  

[FireDAC] [补偿] [DM] -607。映射项[ - > B]的错误文本值[17,5]格式。 ' 17,5'不是有效的整数值。

以上B是我在SQL Server Express中的列名,也是nvarchar(60)

如何实际将数据类型设置为字符串?

我的代码如下。

FDBatchMoveTextReader1.FileName := Edit1.Text;
FDBatchMove1.GuessFormat([taDelimSep, taFields]);

case ComboBox1.ItemIndex of
  0: FDBatchMoveTextReader1.Encoding := ecANSI;
  1: FDBatchMoveTextReader1.Encoding := ecDefault;
  2: FDBatchMoveTextReader1.Encoding := ecUTF16;
  3: FDBatchMoveTextReader1.Encoding := ecUTF8;
end;

for i := 0 to FDBatchMoveTextReader1.DataDef.Fields.Count-1 do begin
  // Set all field data type as string
  FDBatchMoveTextReader1.DataDef.Fields[i].DataType := atString;
end;

FDBatchMove1.Execute;

1 个答案:

答案 0 :(得分:0)

下面解决了问题:

FDBatchMoveTextReader1.FileName := Edit1.Text;
FDBatchMove1.GuessFormat([taDelimSep, taFields]);

case ComboBox1.ItemIndex of
  0: FDBatchMoveTextReader1.Encoding := ecANSI;
  1: FDBatchMoveTextReader1.Encoding := ecDefault;
  2: FDBatchMoveTextReader1.Encoding := ecUTF16;
  3: FDBatchMoveTextReader1.Encoding := ecUTF8;
end;

for i := 0 to FDBatchMoveTextReader1.DataDef.Fields.Count-1 do begin
  // Set all field data type as string
  FDBatchMoveTextReader1.DataDef.Fields[i].DataType := atString;
end;

FDBatchMove1.Analyze := [];

FDBatchMove1.Execute;

感谢你让我处于严谨的方向。