G
Guest
I'm attempting to retrieve a bitmap from an image field in SQL Server 2005
using Visual Studio 2005 C#. I then want to load the bitmap into a
picturebox. When I run the following code, I get the error message:
Parameter is no valid.
Debugging shows that the Image.FromStream(ms) statement is the culprit.
Anyone know what I'm doing wrong?
-----------------------------------------
using (SqlConnection sqlConn = new SqlConnection(builder.ConnectionString))
{
sqlConn.Open();
SqlDataAdapter sql = new SqlDataAdapter(
"SELECT Picture FROM Pictures WHERE Pictures.CardID=5", sqlConn);
DataSet ds1 = new DataSet();
sql.Fill(ds1, "Pictures");
DataRow dr = ds1.Tables["Pictures"].Rows[0];
byte[] result = (byte[])dr["Picture"];
int ArraySize = result.GetUpperBound(0);
MemoryStream ms = new MemoryStream(result, 0, ArraySize);
pictureBox1.Image = Image.FromStream(ms);
sqlConn.Close();
}
using Visual Studio 2005 C#. I then want to load the bitmap into a
picturebox. When I run the following code, I get the error message:
Parameter is no valid.
Debugging shows that the Image.FromStream(ms) statement is the culprit.
Anyone know what I'm doing wrong?
-----------------------------------------
using (SqlConnection sqlConn = new SqlConnection(builder.ConnectionString))
{
sqlConn.Open();
SqlDataAdapter sql = new SqlDataAdapter(
"SELECT Picture FROM Pictures WHERE Pictures.CardID=5", sqlConn);
DataSet ds1 = new DataSet();
sql.Fill(ds1, "Pictures");
DataRow dr = ds1.Tables["Pictures"].Rows[0];
byte[] result = (byte[])dr["Picture"];
int ArraySize = result.GetUpperBound(0);
MemoryStream ms = new MemoryStream(result, 0, ArraySize);
pictureBox1.Image = Image.FromStream(ms);
sqlConn.Close();
}