| | |
SQL Server, Images and DataGrid in ASP.NET
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 19
Reputation:
Solved Threads: 1
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
Also how to retrieve those saved images from SQL Server and display them onto DataGrid.
Visit: http://www.programmingknowledge.com/ImageUpload.aspx
•
•
Join Date: Jul 2006
Posts: 47
Reputation:
Solved Threads: 0
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
Then you need to set up a SQL Connection, Command, and DataReader, read the binary data and then write it to the page:
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.
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)
Dim iConn As New Data.SqlClient.SqlConnection("-Connection String Here-") Dim iCmd As New Data.SqlClient.SqlCommand("SELECT image FROM IMAGES WHERE image_id = " & ImageID, iConn) Dim iRead As Data.SqlClient.SqlDataReader iConn.Open() iRead = iCmd.ExecuteReader() Response.BinaryWrite(iRead("image")) 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.
•
•
Join Date: May 2006
Posts: 19
Reputation:
Solved Threads: 1
There is an example at
http://www.programmingknowledge.com/ImageUpload.aspx
http://www.programmingknowledge.com/ImageUpload.aspx
![]() |
Similar Threads
- Need Freelance ASP.NET, MS SQL, C#, VB.NET Developer (Web Development Job Offers)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- are C#, VB.NET, ASP.NET part of new VS.NET? (ASP.NET)
- SQL SERVER 2000 Login failure in ASP.NET (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Need Suggestion regarding sending sms through asp.net app
- Next Thread: Print a web page in ASP.net
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal formview gridview gudi iis javascript list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview unauthorized validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





