what is wrong with the foll code?

  • Thread starter Thread starter shin
  • Start date Start date
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?
 
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.
 
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
 
Back
Top