我编写了这段代码来读取存储在 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();
}