Retrieve image from Sql
-
I am trying to display the Image which i have retrieved from Sql . The problem is i am not able to convert the bytes to image in my webform. This is my Code. SqlCommand scmd = new SqlCommand ("select mImage from MyTable where Title='"+ TextBox1.Text + "'", sqlConn); sqlConn.Open(); Byte[] storedImage = (Byte[])scmd.ExecuteScalar(); Using this i have retrieved the image But how can i display it in the Image control. Can anybody help me to solve this using C#.
VanithaVasu
-
I am trying to display the Image which i have retrieved from Sql . The problem is i am not able to convert the bytes to image in my webform. This is my Code. SqlCommand scmd = new SqlCommand ("select mImage from MyTable where Title='"+ TextBox1.Text + "'", sqlConn); sqlConn.Open(); Byte[] storedImage = (Byte[])scmd.ExecuteScalar(); Using this i have retrieved the image But how can i display it in the Image control. Can anybody help me to solve this using C#.
VanithaVasu
Take a step back and think about how HTML works. The browser gets the page from the server. The IMG tag in the page points to where the image data is located. The browser makes a seperate request to get the image. You will need to implement another page (better still an ashx handler), which can write that byte[] out, and set the Response.ContentType to image/jpeg (whatever). Also please have a google for "SQL Injection" and "Parameterized Queries", because as your code stands now, I can delete anything out your database by typing nasty things into TextBox1...
Mark Churchill Director Dunn & Churchill Free Download:
Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio. -
I am trying to display the Image which i have retrieved from Sql . The problem is i am not able to convert the bytes to image in my webform. This is my Code. SqlCommand scmd = new SqlCommand ("select mImage from MyTable where Title='"+ TextBox1.Text + "'", sqlConn); sqlConn.Open(); Byte[] storedImage = (Byte[])scmd.ExecuteScalar(); Using this i have retrieved the image But how can i display it in the Image control. Can anybody help me to solve this using C#.
VanithaVasu
But in my application i am not going to ask user to type the image names and etc , and i am working in vs.net 2.0 with C#. Actually my problem is i have to display different images in treenode of a treeview for that i have stored the details and the images in the sql and i have retrieved the image too. But the thing is i am not able to display the images in my webform. So is there any way to display the images.
VanithaVasu