By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

asp .net / sql / image data type question

P: n/a
Hi all,

I posted this about a week back with no response so I want to try
again. I have a weird questions in regards to working with sql image
data types. I know how to take the image type and convert it into a
picture on the screen. What I have is a situation where I need to read
the image data from one database, store it, and then upload it to
another database. I tried storing it in viewstate and in a byte
variable. I don't know if I am loosing the lenth property or what, but
I cannot get the data from one database to another. So once I read
IMAGE data type out of an sql database, what kind of asp .net variable
can I save it to so I can write it into another database? Thanks all!

Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
I think the way to go is: reading the Image data from the DB to the byte[]
(byte array) using StreamReader and backwards.

Cheers

"ma******@bellsouth.net" wrote:
Hi all,

I posted this about a week back with no response so I want to try
again. I have a weird questions in regards to working with sql image
data types. I know how to take the image type and convert it into a
picture on the screen. What I have is a situation where I need to read
the image data from one database, store it, and then upload it to
another database. I tried storing it in viewstate and in a byte
variable. I don't know if I am loosing the lenth property or what, but
I cannot get the data from one database to another. So once I read
IMAGE data type out of an sql database, what kind of asp .net variable
can I save it to so I can write it into another database? Thanks all!

Nov 19 '05 #2

P: n/a
Pat
Matt try looking through this sample below
http://authors.aspalliance.com/das/readimage.aspx
That should help
Patrick
<ma******@bellsouth.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi all,

I posted this about a week back with no response so I want to try
again. I have a weird questions in regards to working with sql image
data types. I know how to take the image type and convert it into a
picture on the screen. What I have is a situation where I need to read
the image data from one database, store it, and then upload it to
another database. I tried storing it in viewstate and in a byte
variable. I don't know if I am loosing the lenth property or what, but
I cannot get the data from one database to another. So once I read
IMAGE data type out of an sql database, what kind of asp .net variable
can I save it to so I can write it into another database? Thanks all!

Nov 19 '05 #3

P: n/a
I appreciate the advise guys.

Pat,

You are showing me how to display a picture from SQL image type. I have
successfully implemented this already. I need to know how to transfer
this information into another column in another table in another
database. Should be easy, but I am not sure how to.

Alex444,

I do not understand how to do what you have suggested. I will do some
searches. If you could give me more of an example, I would GREATLY
appreciate it.

Thanks again all. You guys are great.
Pat wrote:
Matt try looking through this sample below
http://authors.aspalliance.com/das/readimage.aspx
That should help
Patrick
<ma******@bellsouth.net> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi all,

I posted this about a week back with no response so I want to try
again. I have a weird questions in regards to working with sql image
data types. I know how to take the image type and convert it into a
picture on the screen. What I have is a situation where I need to read
the image data from one database, store it, and then upload it to
another database. I tried storing it in viewstate and in a byte
variable. I don't know if I am loosing the lenth property or what, but
I cannot get the data from one database to another. So once I read
IMAGE data type out of an sql database, what kind of asp .net variable
can I save it to so I can write it into another database? Thanks all!


Nov 19 '05 #4

P: n/a

If the two Databases are on the same server, then do it via SQL insert
statement.

If the Databases are on two different servers under your control, try
using Linked servers and then using the OPENQUERY sql statement.

If you need to use asp.net webform as the medium to transport the data
(for whatever reason, QCing, approving, etc), then hold the Image
(either as Byte array, base64string, whatever) in, maybe, a session
object and when the end user says to store the info into a db, then
take your original code that you did the insert to Database one...and
insert into Database two based on the image that you have stored in the
Session object....

if you need sample code...just post back or pm me..

Ralph
--
rviray
------------------------------------------------------------------------
rviray's Profile: http://www.msusenet.com/member.php?userid=4211
View this thread: http://www.msusenet.com/t-1871081767

Nov 19 '05 #5

P: n/a
Thanks rviray,

The database are on two different server and I do not have control
(just read access) where the image is coming from. I tried using
viewstate to transfer information with not luck. I tried a byte array
but I dont think I read the length correctly. I will try the session
and get back to you. I would need to see code for the byte aray because
I am doing something wrong. Simple version of my code below ( I am
purposely leaving the database configurations out):

Dim my_byt_variable As Byte()
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)

the above format doesn't work for me. I think have to redim the byte
variable with the length of the datareader data

Dim my_byt_variable As Byte()
ReDim bytContent(my_data_reader("my_image").length)
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)

but I don't think this worked for me either. It has been a week since I
have played with it. Need to get back to it I guess. Thanks for your
help.

Nov 19 '05 #6

P: n/a
argh...sorry above on the redim...i mean to use my_byt_variable NOT
bytContent.

Nov 19 '05 #7

P: n/a
I just tried it with session and it does not work. I loaded the image
field into a datareader and then into a session variable. I made a
connection to the new database and wrote the session variable to the
image column. When a reload the picture it is blank.

Nov 19 '05 #8

P: n/a
man....I finally got it. I'm ashamed of myself.

I had a syntax error in my page that displays the image, but since I
bound this page to an img tag(the one with the error), I wasn't getting
an error message. Just a picture not displayed. I tried loading the
page bound to my img tag and got the error and fixed it. Storing in
session variable worked fine. Thanks all.

Nov 19 '05 #9

P: n/a
B
Matt,

You specify in one of your posts that you already retreive your images from
the SQL DB. Could you post an example or send it to me on how to do that?

I can upload images into my SQL DB, but can't retreive them in a GridView or
DetailsView. I'm using ASP.NET 2.0 and VB.NET.

Thanks for your help,
Bart

"ma******@bellsouth.net" wrote:
Thanks rviray,

The database are on two different server and I do not have control
(just read access) where the image is coming from. I tried using
viewstate to transfer information with not luck. I tried a byte array
but I dont think I read the length correctly. I will try the session
and get back to you. I would need to see code for the byte aray because
I am doing something wrong. Simple version of my code below ( I am
purposely leaving the database configurations out):

Dim my_byt_variable As Byte()
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)

the above format doesn't work for me. I think have to redim the byte
variable with the length of the datareader data

Dim my_byt_variable As Byte()
ReDim bytContent(my_data_reader("my_image").length)
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)

but I don't think this worked for me either. It has been a week since I
have played with it. Need to get back to it I guess. Thanks for your
help.

Dec 23 '05 #10

P: n/a
I don't know if my way is conventional. Here is what I do.

The page that requests an image uses as session variable to hold the
primary key information for the record I am looking for. This page also
has an img tag bound to a 2nd page that will load the picture. I check
to see if there is picture data, and if there is, I make the img tag
visible that is bound to the page showing the picture. I'm not very
experienced with this stuff, but I was able to get it to work this way.
So again,

1) user click a data grid in order to see a picture.
2) I pass the primary key for that record based on previous click to
session
3) I check to see if picture data is there and show the img tag bound
to a 2nd page that will output the picture based on the session
variable.

here is my img tag:

<img id ="img_email_picture_lenel" src="picture_lenel.aspx"
height="300" width="250" runat="server">

Here is my datagrid code:

If e.commandname="picture" Then
Dim cmd_load_picture As SqlCommand
Dim dtr_load_picture As SqlDataReader

'Dim str_blob_length As String

cmd_load_picture = New SqlCommand ("SELECT * FROM mmobjs WHERE
empid='" & session("empid") & "'", conMatt_I3)
dtr_load_picture = cmd_load_picture.ExecuteReader()

If dtr_load_picture.read() = false Then
div_person_lookup_no_picture.visible = true 'shows alert div
stating no photo available
img_person_lookup_lenel.visible = false 'hides lenel picture
because there isn't one
img_person_lookup_none.visible = true 'shows image for no photo
available
Else
div_person_lookup_no_picture.visible = false 'hides alert div
stating no photo available
img_person_lookup_lenel.visible = true ' show lenel picture
img_person_lookup_none.visible = false 'hide no photo picture
'Response.Write("<Script
language='javascript'>window.open('picture.aspx',n ull,'height=300,
width=300, status= no, resizable= no, scrollbars=yes,
toolbar=no,location=no,menubar=no, left=900, top=100 ');" & chr(60) &
"/script>")
End If
End If
Here is the page showing the picture:
Sub Page_Load
conMatt_I3.Open()

Dim cmdLoadAttachment As SqlCommand
Dim dtrLoadAttachment As SqlDataReader

'Dim str_blob_length As String

cmdLoadAttachment = New SqlCommand ("SELECT * FROM mmobjs WHERE
empid='" & session("empid") & "'", conMatt_I3)
dtrLoadAttachment = cmdLoadAttachment.ExecuteReader()
dtrLoadAttachment.Read()
Response.Buffer = True
Response.ContentType = "Image/BMP"
Response.BinaryWrite(dtrLoadAttachment("lnl_blob") )
dtrLoadAttachment.Close()

Hope this helps you.
End Sub
B wrote:
Matt,

You specify in one of your posts that you already retreive your images from
the SQL DB. Could you post an example or send it to me on how to do that?

I can upload images into my SQL DB, but can't retreive them in a GridView or
DetailsView. I'm using ASP.NET 2.0 and VB.NET.

Thanks for your help,
Bart

"ma******@bellsouth.net" wrote:
Thanks rviray,

The database are on two different server and I do not have control
(just read access) where the image is coming from. I tried using
viewstate to transfer information with not luck. I tried a byte array
but I dont think I read the length correctly. I will try the session
and get back to you. I would need to see code for the byte aray because
I am doing something wrong. Simple version of my code below ( I am
purposely leaving the database configurations out):

Dim my_byt_variable As Byte()
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)

the above format doesn't work for me. I think have to redim the byte
variable with the length of the datareader data

Dim my_byt_variable As Byte()
ReDim bytContent(my_data_reader("my_image").length)
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)

but I don't think this worked for me either. It has been a week since I
have played with it. Need to get back to it I guess. Thanks for your
help.


Jan 9 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.