操作数类型冲突:image与varchar不兼容

cbc 2006-04-20 10:12:48
为了实现向数据库中添加数据,代码如下:
SQL.Add('insert into examination(topic,type,answer,difficulty,mark,requirement,people,data)');
SQL.Add('values(:topic,:type,:answer,:difficulty,:mark,:requirement,:people,:date)');
Parameters.ParamByName('topic').DataType := ftBlob; // ftBlob
Parameters.ParamByName('topic').Value := StreamToVariant(streamQ);
Parameters.ParamByName('type').Value := ComboBox1.Text;
Parameters.ParamByName('answer').Value := nA.Text;
ExecSQL;

但运行时会出现这样的错误:
操作数类型冲突:image与varchar不兼容
...全文
589 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbc 2006-04-20
  • 打赏
  • 举报
回复
ithinkthereforeiam,
你这样改是可以了,请问数据库中能否保存图片数据
ithinkthereforeiam 2006-04-20
  • 打赏
  • 举报
回复
改成下面这样
SQL.Add('insert into examination(Enum,topic,type,answer,difficulty,mark,requirement,people,data)');
SQL.Add('values(:Enum,:topic,:type,:answer,:difficulty,:mark,:requirement,:people,:date)');
Parameters.ParamByName('Enum').Value := '12';
Parameters.ParamByName('topic').Value := nQ.Text;
Parameters.ParamByName('type').Value := ComboBox1.Text;
Parameters.ParamByName('answer').Value := nA.Text;
ExecSQL;
cbc 2006-04-20
  • 打赏
  • 举报
回复
ithinkthereforeiam(),
因Enu是key,不能为空的;
我在SQL中增加了一句,
Parameters.ParamByName('Enum').Value := '12';
报错:

csql:Parameter 'Enum' not found
cbc 2006-04-20
  • 打赏
  • 举报
回复
xjwy(程序春秋) ,我是传一段文本数据;
请问图片或公式数据也能传吗?
ithinkthereforeiam 2006-04-20
  • 打赏
  • 举报
回复
你没给Enum字段赋值,而数据库中又不允许为空,就报这个错
要不你设置称允许空值,要不你在sql语句中给该字段赋值
xjwy 2006-04-20
  • 打赏
  • 举报
回复
varchar是一个指针,你到底要传什么数据?图片?
cbc 2006-04-20
  • 打赏
  • 举报
回复
DeadWolf,按你的改发;
会出现下面的错误:

“无法将NULL值插入列'Enum',表'test.dbo.examination';该列不允许空值。Insert失败”
cbc 2006-04-20
  • 打赏
  • 举报
回复
无法将NULL值插入列'Enum',表'test.dbo.examination';该列不允许空值。Insert失败
DeadWolf 2006-04-20
  • 打赏
  • 举报
回复
Parameters.ParamByName('topic').DataType := ftString;

Parameters.ParamByName('topic').Value := nQ.Text;
ithinkthereforeiam 2006-04-20
  • 打赏
  • 举报
回复
又是啥错啊?
cbc 2006-04-20
  • 打赏
  • 举报
回复
Parameters.ParamByName('topic').DataType := ftBlob;
这句化注释掉会出现新的错误
ithinkthereforeiam 2006-04-20
  • 打赏
  • 举报
回复
咋了,还报那个错?
下面这句话也应该注释掉
Parameters.ParamByName('topic').DataType := ftBlob;
cbc 2006-04-20
  • 打赏
  • 举报
回复
不用流还是不行, 改为
Parameters.ParamByName('topic').Value := nQ.Text;
nQ: TStringList;
ithinkthereforeiam 2006-04-20
  • 打赏
  • 举报
回复
你数据库字段的类型是varchar,而你参数值是一个流,那就有冲突了,要不你把字段改成image,要不就把传给参数值改成一个字符串
cbc 2006-04-20
  • 打赏
  • 举报
回复
不是的,topic是varchar类型
ithinkthereforeiam 2006-04-20
  • 打赏
  • 举报
回复
topic是image类型?
chkdsk21 2006-04-20
  • 打赏
  • 举报
回复
首先需要用TBlobField對字段進行強制轉換,另,數據庫中最好用NTEXT,TEXT,IMAGE類型。
DeadWolf 2006-04-20
  • 打赏
  • 举报
回复
不能直接用insert SQL语句

需要使用TBlobField LoadFromStream 方法
或者 TDataSet 的 CreateBlobStream


给你贴个帮助上的示例

var
MS: TMemoryStream;
begin
if not (ClientDataSet1.State in [dsInsert, dsEdit]) then
ClientDataSet1.Insert;
MS := TMemoryStream.Create();
try
Image1.Picture.Bitmap.SaveToStream(MS);
ClientDataSet1Images.LoadFromStream(MS);
finally
MS.Free;
end;
ClientDataSet1.Post;
end;
DeadWolf 2006-04-20
  • 打赏
  • 举报
回复
当然可以保存图片数据

不过不能一次性完成了

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧