我在数据库中定义的blob类型储存图片
先读取图片数据:
byte[] picture;
FileStream myStream = (FileStream)openImageFileDialog.OpenFile();
picture = new byte[myStream.Length];
myStream.Read(picture, 0, (int)myStream.Length);
插入数据库
string strSql = string.Format("Insert into Image(id,picture) values(null,@picture)");
 MySqlCommand cmd = new MySqlCommand(strSql,con);    
cmd.Parameters.Add("@picture", picture);
 cmd.ExecuteNonQuery();
这样,但是我执行结果里没有数据,调试内存中picture有值
请各位帮忙看mysql图片存储要怎么做,谢谢先

解决方案 »

  1.   


    MySql不支持直接在sql   语句中使用参数,可以建立一个存储过程,然后把图片通过参数传到存储过程中,在存储过程内部把图片进行保存.
      

  2.   

    我如果不写存储过程,直接插入bolb类型的数据,又要怎么做呢?
    string   strSql   =   string.Format("Insert   into   Image(id,picture)   values(null,{0})",picture); 
    这样不行
      

  3.   

    if (Connection != null) 
                {
                    Connection.Dispose();
                    Connection = null;
                }                
            }