日期:2014-05-18  浏览次数:20671 次

c#在sqlite下如何存储文件?
字段的类型是iamge还是blob。为啥我在新增的时候会出错

  #region Sql脚本
  var sql = @"INSERT INTO [Cust_MMSAccessaryTB](
  [MMSAccessaryID]
  ,[FileContent]
  ,[FileName]
  ,[FileExtension]
  )VALUES(
  @AccessaryID
  ,@FileContent
  ,@FileName
  ,@FileExtension
  )";
  #endregion

  //取得附件表表最大唯一标识
  entity.MMSAccessaryID = DbHelper.Instance.GetMaxID("Cust_MMSAccessaryTB");

  //参数列表
  var parameters = new List<SQLiteParameter>()
  {
  new SQLiteParameter("MMSAccessaryID", entity.MMSAccessaryID),
  new SQLiteParameter("FileContent", entity.FileContent),
  new SQLiteParameter("FileName", entity.FileName),
  new SQLiteParameter("FileExtension", entity.FileExtension)
  };


  //执行操作
  result.IsOK = DbHelper.ExecuteNonQuery(sql, parameters.ToArray()) > 0;


------解决方案--------------------
SQLite沒有IMAGE类型吧。好像只有BLOB
------解决方案--------------------
保存路径吧。
------解决方案--------------------
VALUES 后面跟的 @AccessaryID 等,换成 :AccessaryID
------解决方案--------------------
SQLite的参数前导符号就是@。不过创建参数那里倒是有问题,应该是
C# code

  //参数列表
  var parameters = new List<SQLiteParameter>()
  {
  new SQLiteParameter("@AccessaryID", entity.MMSAccessaryID),
  new SQLiteParameter("@FileContent", entity.FileContent),
  new SQLiteParameter("@FileName", entity.FileName),
  new SQLiteParameter("@FileExtension", entity.FileExtension)
  };

------解决方案--------------------
参数要跟sql语句对应。另外不知道lz的DbHelper.Instance.GetMaxID方法是怎么样的,如果是返回表主键的最大值的话应该+1后再付给entity插入到数据库中