winform下:
//存储
private void MemoryImage()
{
string sql = "";
//string conn = "Provider=SQLNCLI;Data Source=192.168.0.9,1433;Database=WebDown;UID=sa;PWD=111122;";
Stream ms;
byte[] picbyte;
OpenFileDialog ofdSelectPic = new OpenFileDialog();
if (ofdSelectPic.ShowDialog() == DialogResult.OK)
{
if ((ms = ofdSelectPic.OpenFile()) != null)
{
picbyte = new byte[ms.Length];
ms.Position = 0;
ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));
//连接数据库
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=192.168.0.9,1433;Database=WebDown;UID=sa;PWD=111122;";
sql = "Insert into LibraryCover(Cover) values(@UpdateImage)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@UpdateImage", SqlDbType.VarBinary);
cmd.Parameters["@UpdateImage"].Value = picbyte;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
ms.Close();
}
}
MessageBox.Show("完成!");
}
//读取
private void ShowImage()
{
string sql = "";
sql = "sele