私はこのコードを持っていました。私が取得する未処理の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#の初心者ですから、私はそれらのエラーに精通していません。
私はSharkに同意します。ここでの問題はデータ型の不一致です –