我正在尝试使用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;
答案 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;
感谢你让我处于严谨的方向。