473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

what is wrong with the foll code?

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?


Nov 17 '05 #1
3 1309
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.

"shin" <as**@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 17 '05 #2
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.

"shin" <as**@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 17 '05 #3
Dim con As New SqlConnection("Server=server1;uid=sa;pwd=guest;dat abase=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
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
4
by: Chris | last post by:
Hi, What's the best way to check if two or more textboxes are empty before executing a task? I have the foll which is NOT WORKING If Not (txtDateFrom.Text Is Nothing) And (txtDateTo.Text Is...
2
by: Reiro | last post by:
Hi ppl the foll: code calls a query that inserts the data into a table through parameters... is my sql statement correct... My table is created in design view.... Private Sub...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.