943,973 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 13791
  • ASP.NET RSS
Aug 20th, 2006
0

SQL Server, Images and DataGrid in ASP.NET

Expand Post »
How to upload Images to SQL Server database using ASP.NET tools.
Also how to retrieve those saved images from SQL Server and display them onto DataGrid.
Visit: http://www.programmingknowledge.com/ImageUpload.aspx
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
postmaster is offline Offline
19 posts
since May 2006
Aug 23rd, 2006
0

Re: SQL Server, Images and DataGrid in ASP.NET

u want to store the images in the database

if that wht u want to do, i dont suggest that

instead i will tell u to store the file path in a table in the database and then when u want to view the image u select its path from the database.

that wht i will do
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
web_developer is offline Offline
84 posts
since Mar 2006
Aug 29th, 2006
0

Re: SQL Server, Images and DataGrid in ASP.NET

Image data is stored on a SQL database as binary data, and must be read as such. In order to create this DataGrid, you will need the page that it is on, say Default.aspx and another page to gather and display the image, say IMG.aspx. First look at IMG.aspx:

We need to read the binary data and output it within the page. We also need something to tell us what the id of the picture is in our database table. For this we will create a query in our URL. So the url of each image will be .../IMG.aspx?ID=XX, XX being the images ID. Then, in the code for that page, we gather the query value using Dim ImageID As Integer = Request.QueryString("ID")

Then you need to set up a SQL Connection, Command, and DataReader, read the binary data and then write it to the page:
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. Dim iConn As New Data.SqlClient.SqlConnection("-Connection String Here-")
  3. Dim iCmd As New Data.SqlClient.SqlCommand("SELECT image FROM IMAGES WHERE image_id = " & ImageID, iConn)
  4. Dim iRead As Data.SqlClient.SqlDataReader
  5.  
  6. iConn.Open()
  7. iRead = iCmd.ExecuteReader()
  8. Response.BinaryWrite(iRead("image"))
  9. iConn.Close()

Then, on Default.aspx, you add the datagrid and, instead of reading the binary data for the image from the database, you read the images ID, and add that to the url for the IMG.aspx page, which you then databind to an image or imagebutton's imageurl property.
Reputation Points: 10
Solved Threads: 0
Light Poster
ChimpusDupus is offline Offline
47 posts
since Jul 2006
Sep 14th, 2006
0

Re: SQL Server, Images and DataGrid in ASP.NET

Reputation Points: 10
Solved Threads: 1
Newbie Poster
postmaster is offline Offline
19 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Need Suggestion regarding sending sms through asp.net app
Next Thread in ASP.NET Forum Timeline: Print a web page in ASP.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC