winform下:
//存儲
private void MemoryImage()
{
string sql = "";
//string conn = "Provider=SQLNCLI;Da
Stream ms;
byte[] picbyte;
OpenFileDialog fdSelectPic = 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 = "Da
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 = "";
&nb