SQL Server データベースに保存されている画像を読み取るためにこのコードを書きましたが、次のエラーが発生しました。
ExecuteScalar: 接続プロパティが初期化されていません。
すでに接続を初期化しているため、何が問題なのかわかりません。
SqlConnection myConnection = null;
try
{
myConnection = new SqlConnection("Data Source=Source; Initial Catalog=Database; user ID=Test; Password=Test");
SqlCommand myCommand = new SqlCommand ("SELECT imagedata FROM Database , myConnection");
myConnection.Open();
// Get the image from the database.
byte[] imagedata = (byte[])myCommand.ExecuteScalar();
if (imagedata != null)
{
return image;
}
else
{
return null;
}
}
finally
{
myConnection.Close();
}