Я написал этот код для чтения изображений, хранящихся в базе данных SQL Server, однако я получил эту ошибку:ExecuteScalar: свойство Connection не инициализировано. SQL Server Connection
ExecuteScalar: Connection property has not been initialized.
Поскольку я уже инициализирован связь, я не уверен, что проблема есть.
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();
}