高手帮忙看一下C#+Mysql存储位图时不正确
源代码如下:
m_con = new MySqlConnection();
m_con.ConnectionString = "server=192.168.0.100;user id=coolspring;password=qweasdzxc;database=test";
try
{
m_con.Open();
lblInfo.ForeColor = Color.White;
lblInfo.Text = "连接成功";
}
catch (MySqlException e1)
{
lblInfo.ForeColor = Color.Red;
lblInfo.Text = e1.Message;
return;
}
FileStream fs = new FileStream("e:\\temptest\\1.bmp", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
int filelen =(int)fs.Length;
byte[] bt = new byte[filelen];
fs.Read(bt, 0, filelen);
fs.Close();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = m_con;
cmd.CommandText = "update blobtest set binarybmp=?aid where idBlobTest='1'";
MySqlParameter para = new MySqlParameter("aid", MySqlDbType.Blob, bt.Length, ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Current, bt);
cmd.Parameters.Add(para);
try
{
cmd.ExecuteNonQuery();
}
catch (MySqlException e2)
{
lblInfo.Text = e2.Message;
}
问题:
1.改变位图文件,有的能成功(但是从Mysql workbench中读取时字节数不对),有的直接提示出错
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 '{y剉? a堇2\'糎B DT@埢?湨nD软? 蜭3臯?0?\0見?V橘5 k犬 叆?i I弆鸮仗V' at line 1
2.后来我打开一个0~255的二进制文件,保存成功并且在mysql workbench中也保存无误,但是换成位图还是不成功!!
搞了一天,没搞定,请高手指点,谢谢