我有这个代码;我得到的未处理的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