Example : How to Edit/Modify/Update the Data/Record of the SQL Server Database

How to update the database record normally

Try
   cn.Open()
   cm.CommandText = "UPDATE CDETAIL SET CATE='" + COMCATE.Text + "',CNAME=
   '" + comCNAME.Text + "',PDUES='" + TXTPDUES.Text + "',CSAMOUNT=
   '" + TXTCSAMOUNT.Text + "',ATOPAY='" + TXTATOPAY.Text + "',PAMOUNT=
   '" + TXTPAMOUNT.Text + "',CDUES='" + TXTCDUES.Text + "',REMS=
   '" + TXTREMS.Text + "'WHERE CODE='" + COMCODE.Text + "'"

   Dim i As Integer = cm.ExecuteNonQuery
   cn.Close()
   MsgBox(i.ToString + " RECORD UPDATE SUCCESSFULLY")
Catch ex As Exception
   MsgBox(ex.Message)
Finally
   cn.Close()
End Try

How to update the record  with confirmation message

Dim i, t, k  As Integer
t = 0
k = MsgBox("Do You want to modify the record...? ", MsgBoxStyle.YesNo)
If k = 6 Then
Try
   cn.Open()
   cm.CommandText = "UPDATE newdealersentry SET activatekey=0, CNAME=
   '" + comCNAME.Text + "'WHERE slno between " + TxtFSlNo.Text + " And " +   
   TxtTSlNo.Text + ""

   i = cm.ExecuteNonQuery
   cn.Close()
   t = t + i
Catch ex As Exception
   MsgBox(ex.Message)
Finally
   cn.Close()        
   MsgBox(t.ToString + " Record Modified")
End Try

Loading

Categories: VB .Net Codes

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.