473,386 Members | 1,710 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,386 software developers and data experts.

asp .net / sql / image data type question

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
10 3187
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
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
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

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
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
argh...sorry above on the redim...i mean to use my_byt_variable NOT
bytContent.

Nov 19 '05 #7
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicolas Keller | last post by:
Hi! I'm used to have Mozilla for testing my PHP sites when I'm coding. The site's nearly finished, now I've made a test with the Internet Exlporer... guess what... failed. The problem: I'm...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: John Dunlop | last post by:
(Note crosspost and follow-ups to ciwah.) Nicolas Keller wrote in thread "Differences in form handling btw Mozilla and IE?": > The problem: I'm using a form that submit's (POST) its data via...
1
by: Josué Maldonado | last post by:
Hello list, That's the question, what is the equivalent data type of the msSQL image data type ? TIA, -- Josué Maldonado.
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
3
by: =?Utf-8?B?SlA=?= | last post by:
Explanation: We have several SP that need to retrieve a single "Default Photo" from one of several Photo tables. The column in question in these tables is defined as an IMAGE data type. I...
1
by: jamal8t2 | last post by:
<?php //$file_dir="/htdocs/upload"; // Connect to database $db_name1="test";// Database name $conn1=mysql_connect("localhost","","") or die("I Couldn't connect"); ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.