Database Reference
In-Depth Information
imageConnection = new SqlConnection(@"data source = .\sql2012;
integrated security = true; initial catalog = SQL2012db;");
imageCommand = new SqlCommand(@" select imagefile,imagedata
from ImageTable", imageConnection);
// Open connection and create data reader
imageConnection.Open();
imageReader = imageCommand.ExecuteReader();
}
public Bitmap GetImage()
{
MemoryStream ms = new MemoryStream(imageBytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
public string GetFilename()
{
return imageFilename;
}
public bool GetRow()
{
if (imageReader.Read())
{
imageFilename = (string)imageReader.GetValue(0);
imageBytes = (byte[])imageReader.GetValue(1);
return true;
}
else
{
return false;
}
}
public void EndImages()
{
// Close the reader and the connection.
imageReader.Close();
imageConnection.Close();
}
}
}
9. Next, insert the code in Listing 18-3 into Displaylmages.cs in the constructor.
You can access Displaylmages.cs by right-clicking Displaylmages.cs and
selecting View Code, which will take you to the Code view.
Search WWH ::




Custom Search