what is wrong with the foll code?

S

shin

hi i am trying to output an image which i have in a database.

but this gives me errors

byte[] Picture;

Picture = (dr["logo"]); //cannot convert from object to byte

Response.Buffer=true;

Response.ContentType = "Image/JPEG";

Response.BinaryWrite(Picture);

how do i output images at a specific position?

do i need to use an image control?
 
K

Kevin Spencer

If the error is "cannot convert from object to byte array" then of course,
what you need to do is to convert from object to byte array. The way you're
getting the data from your DataReader (I presume it's a DataReader?) is
always going to return a type of Object. Instead, use the (not sure which
type of DataReader you're using - I'll go with SqlDataReader)
SqlDataReader.GetByte() method to return the value as the correct type.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
C

chris

Dim con As New SqlConnection("Server=server1;uid=sa;pwd=guest;database=db1")

Dim da As New SqlDataAdapter("Select * From table1", con)

Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)

Dim ds As New DataSet

con.Open()

da.Fill(ds, "table1")

Dim myRow As DataRow

myRow = ds.Tables("table1").Rows(0)

Dim MyData() As Byte

MyData = myRow("logo")

Response.Buffer = True

Response.ContentType = "Image/JPEG"

Response.BinaryWrite(MyData)





this is the vb code that works fine. but i am writing a c# app and i need to
convert the above small piece of code to c#

byte[] Picture;

Picture = (dr["logo"]); //ERROR cannot convert from object to byte

Response.Buffer=true;

Response.ContentType = "Image/JPEG";

Response.BinaryWrite(Picture);




i dont understand what i am doing wrong?



thanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top