我有這個代碼;我得到的未處理的SQLException來自哪裏?
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection cnn;
string connectionString;
connectionString = "server=.\\sqlexpress;database=Blue;trusted_connection=true";
cnn = new SqlConnection(connectionString);
MemoryStream stream = new MemoryStream();
cnn.Open();
SqlCommand command = new SqlCommand("select Image from ImageParts where ImageName=" + listBox1.SelectedIndex, cnn);
byte[] image = (byte[])command.ExecuteScalar();
stream.Write(image, 0, image.Length);
cnn.Close();
Bitmap bitmap = new Bitmap(stream);
pictureBox1.Image = bitmap;
}
我已經存儲在listBox1.Items
然後ImageName
,該錯誤出現。
將varchar值'c1.jpg'轉換爲數據類型爲int的數據 時轉換失敗。
可能是什麼問題?由於我是C#的新手,我不熟悉這些錯誤。
我同意鯊魚,這裏的問題是數據類型不匹配 – 2012-02-28 20:07:21