请看以下代码, 其中SourceDataSet为源数据集, AdoTab为目标数据集,两个都是*.mdb
数据表.我想将SourceDataset中某些的字段(字段名保存在sstrField : TStringList中)的值一个一个的添加到AdoTab中,
nCol:=sstrField.Count;
nRow:=SourceDataSet.RecordCount;
SourceDataSet.DisableControls;
for i:=1 to nRow do
begin
AdoTab.Append;
for n:=1 to nCol do
begin //填入数据
strFieldName:=sstrField.Strings[n-1];
AdoTab.FieldByName(strFieldName).AsString:=SourceDataSet.fieldbyname(strFieldName).AsString;
end;
SourceDataSet.Next;
AdoTab.Post;
end;
但运行完成后,发现AdoTab的每一条从SourceDataSet导入的记录都含有很多空格比如 SourceDataSet中的'联系人'字段值为 '杨文', 导出到AdoTab中以后变成了
"杨文 ',后面空格的长度加上'杨文'两字的长度正好就是该字段的数据长
度!
请问为是怎么回事?!谢谢
数据表.我想将SourceDataset中某些的字段(字段名保存在sstrField : TStringList中)的值一个一个的添加到AdoTab中,
nCol:=sstrField.Count;
nRow:=SourceDataSet.RecordCount;
SourceDataSet.DisableControls;
for i:=1 to nRow do
begin
AdoTab.Append;
for n:=1 to nCol do
begin //填入数据
strFieldName:=sstrField.Strings[n-1];
AdoTab.FieldByName(strFieldName).AsString:=SourceDataSet.fieldbyname(strFieldName).AsString;
end;
SourceDataSet.Next;
AdoTab.Post;
end;
但运行完成后,发现AdoTab的每一条从SourceDataSet导入的记录都含有很多空格比如 SourceDataSet中的'联系人'字段值为 '杨文', 导出到AdoTab中以后变成了
"杨文 ',后面空格的长度加上'杨文'两字的长度正好就是该字段的数据长
度!
请问为是怎么回事?!谢谢
SourceDataSet.fieldbyname(strFieldName).AsString的值是正常的啊
另外空格在某些字段中可能是必要的!
还是老问题???
具体操作查查老帖,我有发过的。