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

c#在mysql中保存图片文件流一直是空值
mysql 版本是 5.1.59
CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `picture` blob,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin

vs2005 sp1 
string file = @"你的图片路径";
byte[] bytes = null;  
bytes = File.ReadAllBytes(file);    
using (MySqlConnection conn = new MySqlConnection(strcon)) 
{            
  using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand() )
  {  
  cmd.CommandText = "insert into test(picture) values(@picture)";
  cmd.CommandType = CommandType.Text;

  cmd.Parameters.Add("@picture", MySql.Data.MySqlClient.MySqlDbType.Blob);
  cmd.Parameters[0].Value = bytes;  
  cmd.Connection = conn;  
  conn.Open();  
   
  int affectedrows = cmd.ExecuteNonQuery();  
   
  cmd.Dispose();  
  conn.Close();  
  }
} 

本人用的是 MySql.Data 5.0.9.0 版本插入是就是空值
当用 MySql.Data 6.4.4.0 插入时候就报语法错误


------解决方案--------------------
insert into test(picture) values(?picture)
oracle是:
只有sqlserver是@