Click here to Skip to main content
15,918,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Dim mstream As New System.IO.MemoryStream()
        Imgupload.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
        Dim arrImage() As Byte = mstream.GetBuffer()
        mstream.Close()
   
        sql = "UPDATE empinfo SET fname=@fname, lname=@lname, oname=@oname, address=@address, dob=@dob, age=@age, gender=@gdr, status=@status" _
        & "city=@city, phone=@phone, pcode=@pcode, state=@state, lg=@lg, cname=@cname, cphone=@cphone, caddress=@caddress, sdate=@sdate, edate=@edate" _
        & "img=@Imgdata, klname=@klname, kfname=@kfname, kphone=@kphone, kaddress=@kaddress, qual=@qual, expr=@expr, lyeardate=@lyeardate" _
        & "pyeardate=@pyeardate, dpermitted=@dpermitted, centitle=@centitle, ctaken=@ctaken, cleft=@cleft, cadre=@cadre" _
        & "WHERE id= '" & txtid.Text & "'"
        Try
            dbcomm = New MySqlCommand(sql, dbconn)
            'dbcomm.Parameters.AddWithValue("@id", txtid.Text)
            dbcomm.Parameters.AddWithValue("@fname", txtfname.Text)
            dbcomm.Parameters.AddWithValue("@lname", txtlname.Text)
            dbcomm.Parameters.AddWithValue("@oname", txtoname.Text)
            dbcomm.Parameters.AddWithValue("@address", txtaddress.Text)
            dbcomm.Parameters.AddWithValue("@dob", DateTimePicker1.Value)
            dbcomm.Parameters.AddWithValue("@age", txtage.Text)
            dbcomm.Parameters.AddWithValue("@gdr", cmbgender.Text)
            dbcomm.Parameters.AddWithValue("@status", cmbstatus.Text)
            dbcomm.Parameters.AddWithValue("@city", txtcity.Text)
            dbcomm.Parameters.AddWithValue("@phone", txtphone.Text)
            dbcomm.Parameters.AddWithValue("@pcode", txtcode.Text)
            dbcomm.Parameters.AddWithValue("@state", cmbstate.Text)
            dbcomm.Parameters.AddWithValue("@lg", txtlg.Text)
            '=========================================================================
            dbcomm.Parameters.AddWithValue("@cname", txtcname.Text)
            dbcomm.Parameters.AddWithValue("@cphone", txtcphone.Text)
            dbcomm.Parameters.AddWithValue("@caddress", txtcaddress.Text)
            dbcomm.Parameters.AddWithValue("@sdate", cdate1.Value)
            dbcomm.Parameters.AddWithValue("@edate", cdate2.Value)
            dbcomm.Parameters.AddWithValue("@imgdata", arrImage)
            dbcomm.Parameters.AddWithValue("@klname", txtklname.Text)
            dbcomm.Parameters.AddWithValue("@kfname", txtkfname.Text)
            dbcomm.Parameters.AddWithValue("@kphone", txtkphone.Text)
            dbcomm.Parameters.AddWithValue("@kaddress", txtcaddress.Text)
            dbcomm.Parameters.AddWithValue("@qual", txtqual.Text)
            dbcomm.Parameters.AddWithValue("@expr", txtexpr.Text)
            dbcomm.Parameters.AddWithValue("@lyeardate", txtlyeardate.Text)
            dbcomm.Parameters.AddWithValue("@pyeardate", txtpyeardate.Text)
            dbcomm.Parameters.AddWithValue("@dpermitted", txtpermitted.Text)
            dbcomm.Parameters.AddWithValue("@centitle", txtcentitle.Text)
            dbcomm.Parameters.AddWithValue("@ctaken", txtctaken.Text)
            dbcomm.Parameters.AddWithValue("@cleft", txtcleft.Text)
            dbcomm.Parameters.AddWithValue("@cadre", cmbcadre.Text)

            dbread = dbcomm.ExecuteReader()

            dbread.Close()
            MsgBox(" Record Updated successfully")
        Catch ex As Exception
            MsgBox("Error is :" & ex.Message)
            dbread.Close()
            Exit Sub
        End Try
        'btnupdate.Enabled = False
    End Sub


What I have tried:

I've tried redefined the parameter but no way. pls help me out
Posted
Updated 22-Aug-16 0:40am
v2
Comments
Patrice T 22-Aug-16 6:36am    
And you plan to tell what is the error message and where ?
Or we have to guess ?

1 solution

Why are you using ExecuteReader on an UPDATE query which by definition returns no rows?
Try changing:
VB
dbread = dbcomm.ExecuteReader()

to
VB
dbcomm.ExecuteNonQuery()
and delete the reader completely.
 
Share this answer
 
Comments
Maciej Los 22-Aug-16 6:41am    
5ed!

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