起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 1543|回复: 30

x32617导入出现数据类型不一致

[复制链接]
发表于 2007-1-11 10:37:38 | 显示全部楼层 |阅读模式
procedure TMainForm.btImportClick(Sender: TObject);
var
  I:Integer;
  lFields,lValues,lInsertSQL:string;
  lFieldList: TFieldList;
begin
  Query1.LoadFromFile('E:        able_sbjbxx.XML');
  lFields:='';
  lValues:='';
  for i:=0 to Query1.FieldCount-1 do
  begin
    if (i<Query1.FieldCount-1) then
    begin
     lFields:=lFields+Query1.FieldList.FieldName+',';
     lValues:=lValues+':'+Query1.FieldList.FieldName+',' ;
    end
    else begin
      lFields:=lFields+Query1.FieldList.FieldName ;
      lValues:=lValues+':'+Query1.FieldList.FieldName;
    end
  end;
  lFields:='('+lFields+')';
  lValues:='Values('+lValues+')';
  lInsertSQL:='Insert into table_sbjbxx '+lFields+' '+lValues;
  QueryInsert.CommandText:=lInsertSQL;
  lFieldList:=Query1.FieldList;

  While not Query1.Eof do
  begin
    for I := 0 to lFieldList.Count - 1 do
    begin
      QueryInsert.Params.AssignFieldValue(lFieldList[I],lFieldList[I].Value);
    end;
    QueryInsert.Execute;//运行该语句时出错
  Query1.Next;
  end ;
end;
当基本信息里有图片时出错,没有图片导入正常。2617是初始化的新系统。

未命名.jpg

13.19 KB, 下载次数: 410

回复

使用道具 举报

发表于 2007-1-11 14:16:36 | 显示全部楼层
正在处理,稍后根贴告知结果,应该不会这样的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-1-15 15:40:10 | 显示全部楼层
有结果码?
回复 支持 反对

使用道具 举报

发表于 2007-1-15 16:49:42 | 显示全部楼层
来结果了:)

经过测试是好的。
你这样,用同一张表导出成XML,然后导进来看看,应该就是导出的类型和导入的类型不一致造成的
回复 支持 反对

使用道具 举报

发表于 2007-1-17 12:07:05 | 显示全部楼层
怎样了?不反馈,我结贴了:)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-1-23 15:22:55 | 显示全部楼层
对不起,因为忙于其它工作,所以没有时间跟贴
导出代码
procedure TMainForm.btExportClick(Sender: TObject);
begin
Query1.CommandText:='select * from table_SBJBXX where SSDW like ''S11JH0340030%''';
Query1.open;
Query1.SaveToFile('E:\SBJBXX_2617.XML',TDatapacketFormat.dfXML) ;

end;
导入代码
procedure TMainForm.btImportClick(Sender: TObject);
var
  I:Integer;
  lFields,lValues,lInsertSQL:string;
  lFieldList: TFieldList;
begin
  Query1.LoadFromFile('E:\SBJBXX_2617.XML');
  lFields:='';
  lValues:='';
  for i:=0 to Query1.FieldCount-1 do
  begin
    if (i<Query1.FieldCount-1) then
    begin
     lFields:=lFields+Query1.FieldList.FieldName+',';
     lValues:=lValues+':'+Query1.FieldList.FieldName+',' ;
    end
    else begin
      lFields:=lFields+Query1.FieldList.FieldName ;
      lValues:=lValues+':'+Query1.FieldList.FieldName;
    end
  end;
  lFields:='('+lFields+')';
  lValues:='Values('+lValues+')';
  lInsertSQL:='Insert into table_SBJBXX '+lFields+' '+lValues;
  QueryInsert.CommandText:=lInsertSQL;
  lFieldList:=Query1.FieldList;

  While not Query1.Eof do
  begin
    for I := 0 to lFieldList.Count - 1 do
    begin
      QueryInsert.Params.AssignFieldValue(lFieldList[I],lFieldList[I].Value);
    end;
    QueryInsert.Execute;//运行该语句时出错
  Query1.Next;
  end ;
end;
仍然出现1楼的错误,因为图片字段插入了jpg文件
回复 支持 反对

使用道具 举报

发表于 2007-1-29 17:24:24 | 显示全部楼层
请用下面的代码修改试验一下。
While not Query1.Eof do
  begin
    for I := 0 to lFieldList.Count - 1 do
    begin
      QueryInsert.Params.DataType := lFieldList[I].DataType;{增加}
      QueryInsert.Params.ParamType := TParamType.ptInput;{增加}
      QueryInsert.Params.AssignFieldValue(lFieldList[I],lFieldList[I].Value);
    end;
    QueryInsert.Execute;//运行该语句时出错
  Query1.Next;
  end ;
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-2-8 16:50:19 | 显示全部楼层
lFieldList:=Query1.FieldList;
  While not Query1.Eof do
  begin
    for I := 0 to lFieldList.Count - 1 do
    begin
      QueryInsert.Params.DataType := lFieldList[I].DataType;{增加}
      QueryInsert.Params.ParamType := TParamType.ptInput;{增加}
      QueryInsert.Params.AssignFieldValue(lFieldList[I],lFieldList[I].Value);
    end;
    QueryInsert.Execute;//运行该语句时出错
    Query1.Next;
  end ;
有图片仍然出现1楼的问题
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-2-27 14:46:42 | 显示全部楼层
??
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-1 14:32:52 | 显示全部楼层
不知道为什么没有人回贴???
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-6-18 15:16 , Processed in 0.050542 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表