Image datatype in SQL eqivalent in .NET?

  • Thread starter Thread starter Michael Lang
  • Start date Start date
M

Michael Lang

I am reading a SQL server datatype "image" field from a SQL server table.
What .NET datatype should I convert it into? That is, what is the
officially correct/best type to convert into?

I am currently working with the sample pubs database. I have a reference to
a single DataRow in the table 'pub_info'...

DataRow dr = ....<bunch of code>
object fieldValue = dr["logo"];
System.Drawing.Image imgLogo = (System.Drawing.Image)fieldValue; // ????

My guess just looks to simple. Does anyone know for sure?

Michael
 
I think you could deal with SQL Server's native datatypes. For example for
image the native .NET type is System.Data.SqlTypes.SqlBinary

See System.Data.SqlTypes Namespace for more details.

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)
 
How do I get the "image" SQL type into a System.Drawing.Image?

You can read the field into a SqlBinary type. Next query the "Value"
property
which returns type "Byte[]". How can I display the picture into a control
such as a picturebox? System.Drawing.Image does not have a constructor or
static method to create an image from a byte array.

Anyone know of samples using the "pubs" database that read the "pub_info"
table, field "logo" which is of type "image"? I want to know how to read
the data, display it in a form, allow the user to browse for a new image,
and save it back to the database. OR any sample doing the same thing with
any database table containing an "image" datatype?

Mike

Teemu Keiski said:
I think you could deal with SQL Server's native datatypes. For example for
image the native .NET type is System.Data.SqlTypes.SqlBinary

See System.Data.SqlTypes Namespace for more details.

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)


Michael Lang said:
I am reading a SQL server datatype "image" field from a SQL server table.
What .NET datatype should I convert it into? That is, what is the
officially correct/best type to convert into?

I am currently working with the sample pubs database. I have a
reference
to
a single DataRow in the table 'pub_info'...

DataRow dr = ....<bunch of code>
object fieldValue = dr["logo"];
System.Drawing.Image imgLogo = (System.Drawing.Image)fieldValue; // ????

My guess just looks to simple. Does anyone know for sure?

Michael
 
Sorry for delay.

You could write bytes to System.IO.MemoryStream. System.Drawing.Image can be
loaded from Stream.

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

Microsoft AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)


Michael Lang said:
How do I get the "image" SQL type into a System.Drawing.Image?

You can read the field into a SqlBinary type. Next query the "Value"
property
which returns type "Byte[]". How can I display the picture into a control
such as a picturebox? System.Drawing.Image does not have a constructor or
static method to create an image from a byte array.

Anyone know of samples using the "pubs" database that read the "pub_info"
table, field "logo" which is of type "image"? I want to know how to read
the data, display it in a form, allow the user to browse for a new image,
and save it back to the database. OR any sample doing the same thing with
any database table containing an "image" datatype?

Mike

Teemu Keiski said:
I think you could deal with SQL Server's native datatypes. For example for
image the native .NET type is System.Data.SqlTypes.SqlBinary

See System.Data.SqlTypes Namespace for more details.

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)


Michael Lang said:
I am reading a SQL server datatype "image" field from a SQL server table.
What .NET datatype should I convert it into? That is, what is the
officially correct/best type to convert into?

I am currently working with the sample pubs database. I have a
reference
to
a single DataRow in the table 'pub_info'...

DataRow dr = ....<bunch of code>
object fieldValue = dr["logo"];
System.Drawing.Image imgLogo = (System.Drawing.Image)fieldValue; // ????

My guess just looks to simple. Does anyone know for sure?

Michael
 
Back
Top