question

Farzana_Tayeb avatar image
Farzana_Tayeb asked

Problem in coding

Protected Sub Search_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Search.Click Connection() Dim cmd As New SqlCommand cmd.Connection = cn cmd.CommandText = "SELECT * FROM Personal_info WHERE Roll_no = '" + TextBox1.Text + "'" Dim objReader As SqlDataReader = cmd.ExecuteReader() If objReader.Read() Then **Image1.Visible = Convert.ToByte(objReader("pic"))** End If cmd.Connection.Close() cmd.Dispose() End Sub Whats the problem in this code Image1.Visible = Convert.ToByte(objReader("pic")) and how I can solve it to retrive image in ASP.net
code
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
Read this. It's not relevant to your question, but may help with a bigger problem in your code. [Little Bobby Tables][1] [1]: http://www.xkcd.com/327
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
up vote for pointing out the risk of SQL Injection
0 Likes 0 ·
ThomasRushton avatar image
ThomasRushton answered
OK. In terms of your line of code that's failing, the `Visible` property of an `Image` object is a boolean - 1 for visible, 0 for invisible. Going by http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx, what you want is something like Image1.FromFile("filename") or Image1.FromStream I can't provide more help than this, as it's not something I've done for, oh, 15 years or so...
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bhuvans avatar image
Bhuvans answered
If it is an ASP.NET , you need to use HTTP Handlers to render an image from database to Image Control. In a query string you need to pass an ImageId, based on ImageID u need retreive the raw data. Render the Data on Page, by mentioning the MIME Type Jpeg or PNG.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.