Hi! I'm trying to Update the database using Datagridview in VB.net. When modify name, address, phone or mobile number and click the update button, other rows(ID) value also changed and same. Pls help me.... thanks in advance
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim str As String
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
If Me.txtID.Text & "" = "" Then
cmd.Connection = cnn
cmd.CommandText = "INSERT INTO CLIENT_REGISTER(CLIENTID,NAME,ADDRESS,PHONE,MOBILE) VALUES ('" & Me.txtID.Text & "','" & Me.txtName.Text & "','" & Me.txtAddress.Text & "','" & Me.txtPhone.Text & "','" & Me.txtMobile.Text & "')"
cmd.ExecuteNonQuery()
End If
cmd.Connection = cnn
str = "UPDATE CLIENT_REGISTER SET NAME='" & Me.txtName.Text & "',ADDRESS='" & Me.txtAddress.Text & "',PHONE='" & Me.txtPhone.Text & "',MOBILE='" & Me.txtMobile.Text & "' WHERE CLIENTID=" & Me.txtID.ReadOnly
cmd = New OleDbCommand(str, cnn)
cmd.ExecuteNonQuery()
RefreshData()
cnn.Close()
VEnable()
Me.btnSave.Enabled = False
Me.btnEdit.Enabled = False
Me.btnUpdate.Enabled = False
Me.btnCancel.Enabled = True
Me.btnNew.Enabled = True
End Sub