mysql 插入byte[]一会儿正确一会儿错误?

feng8080 2012-07-16 10:41:12
我byte[]对应的mysql类型为blob,byte[]大小5000

代码为:
theMySqlCommand.Parameters.Clear();
theMySqlCommand.CommandType = System.Data.CommandType.Text;
theMySqlCommand.CommandText = "insert into fingertemplate (userID, templateID, templateData) values (@userID, @templateID, @templateData);";
MySqlParameter param = new MySqlParameter("@userID", MySqlDbType.UInt32);
param.Value = infoEx.template.userID;
theMySqlCommand.Parameters.Add(param);
param = new MySqlParameter("@templateID", MySqlDbType.Int32);
param.Value = infoEx.template.templateID;
theMySqlCommand.Parameters.Add(param);
param = new MySqlParameter("@templateData", MySqlDbType.Blob);
param.Value = infoEx.template.templateData; //为byte[]
theMySqlCommand.Parameters.Add(param);
reslut = theMySqlCommand.ExecuteNonQuery();

为什么我这样操作有时能插入输入,有时又不能包sql语句错误,我的byte[]也是指纹模板信息。
报错我觉得是byte[]的内容编码引起,但不知掉如何解决。
报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' \a?w[曇?>揎q羼饙 筤.噞h逘 俛W[曇???f _垰??邾&S
侫w[懩閨絿:]灈W堪=宙鍿 0' at line 1
...全文
168 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feng8080 2012-07-16
  • 打赏
  • 举报
回复
我mysql的字符集为gbk
param = new MySqlParameter("@templateData", MySqlDbType.Blob);
param.Value = infoEx.template.templateData; //为byte[]
我觉得是这个byte数组里面有转义字符造成的,这个如何处理呢?
rucypli 2012-07-16
  • 打赏
  • 举报
回复
打印处来sql看看什么时候是报错的 什么时候是不报错的

56,675

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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