Click here to Skip to main content
16,019,043 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dim colname As String = DataGridView1.Columns(e.ColumnIndex).Name
            If colname = "colEdit" Then

                With frmProudctM
                    cn.Open()

                    cm = New MySqlCommand("select image, pid, description, category, costprice, sellingprice from tblproduct where pid like '" & DataGridView1.Rows(e.RowIndex).Cells(1).Value & " ' ", cn)
                    dr = cm.ExecuteReader()
                    While dr.Read
                        Dim len As Long = dr.GetBytes(0, 0, Nothing, 0, 0)
                        Dim arr(CInt(len)) As Byte
                        dr.GetBytes(0, 0, arr, 0, CInt(len))
                        Dim MS As New MemoryStream(arr)
                        Dim Bitmap As New Bitmap(MS)
                        .PictureBox1.Image = Bitmap
                        .lblpid.Text = dr.Item("pid").ToString
                        .txtDescription.Text = dr.Item("description").ToString
                        .cboCategory.Text = dr.Item("category").ToString
                        .txtCostPrice.Text = dr.Item("costprice").ToString
                        .txtSellingPrice.Text = dr.Item("sellingprice").ToString

                    End While
                    dr.Dispose()
                    cn.Close()
                    .btnSubmit.Visible = False
                    .btnUpdate.Visible = True
                    .ShowDialog()
                End With


What I have tried:

I have tried all means but still the same
Posted
Updated 9-May-22 22:02pm
v2
Comments
Rajeev Jayaram 9-May-22 12:49pm    
Did you try to debug? What error you were getting?
matblue25 9-May-22 16:50pm    
Is "frmProudctM" a misspelling in the With statement? Maybe should be frmProductM (or whatever, can't tell from just this snippet).
Richard Deeming 12-May-22 11:45am    
"select image, pid, description, category, costprice, sellingprice from tblproduct where pid like '" & DataGridView1.Rows(e.RowIndex).Cells(1).Value & " ' "

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

1 solution

i searched through the internet the whole night and found the right answer to my question asked......

i created a function below using the below code

Function Byte2Image(ByVal ByteArr() As Byte) As Bitmap
Dim ImageStream As MemoryStream
Try
If ByteArr.GetUpperBound(0) > 0 Then
ImageStream = New MemoryStream(ByteArr)
ImageStream.Seek(0, SeekOrigin.Begin)
Dim bmp As Bitmap = New Bitmap(ImageStream)
Return bmp
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function


......After i used this code in my DGV

Dim img = Byte2Image(DataGridView1.Rows(e.RowIndex).Cells(6).Value)
If img IsNot Nothing Then
.PictureBox1.Image = img
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900