this is my assignment I’ve already finished the adding and deleting of records can anyone help me how to update the records in it check out my code…
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
Dim da As SqlDataAdapter
Dim com As SqlCommand
Dim sql As String
Dim con As New SqlConnection(“Data Source=. \SQLEXPRESS; AttachDbFilename= C:\Users\Chad\Desktop\my assignments\DatabaseConnection\DatabaseC… Integrated Security=True; User Instance=True”)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘TODO: This line of code loads data into the ‘PayrollDataSet.UserAccount’ table. You can move, or remove it, as needed.
Me.UserAccountTableAdapter.Fill(Me.Payro…
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
btnAdd.Enabled = True
btnEdit.Enabled = False
btnDelete.Enabled = False
btnSave.Enabled = True
btnCancel.Enabled = True
enableTextboxes()
clearTextboxes()
txtUserId.Focus()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
btnAdd.Enabled = False
btnEdit.Enabled = True
btnDelete.Enabled = False
btnSave.Enabled = True
btnCancel.Enabled = True
enableTextboxes()
clearTextboxes()
txtUsername.Focus()
filldata()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
ErrorProvider1.Clear()
If btnAdd.Enabled Then
If txtUserId.Text = “” Then
ErrorProvider1.SetError(txtUserId, “Please enter a value”)
txtUserId.Focus()
Else
AddRecord()
ErrorProvider1.Clear()
btnAdd.Enabled = True
btnEdit.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
btnCancel.Enabled = False
disableTextboxes()
End If
ElseIf btnEdit.Enabled Then
If txtUserId.Text = “” Then
ErrorProvider1.SetError(txtUserId, “Please enter a value”)
txtUserId.Focus()
Else
EditRecord()
ErrorProvider1.Clear()
btnAdd.Enabled = True
btnEdit.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
btnCancel.Enabled = False
disableTextboxes()
End If
End If
End Sub
Private Sub btnDelete_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Try
Dim ans, username As String
username = dgvUserAccount.Item(1, dgvUserAccount.CurrentCell.RowIndex).Val…
ans = MessageBox.Show(“Are you sure you want to delete ” & username & “?”, “Confirm Deletion”, MessageBoxButtons.YesNo)
If (ans = vbYes) Then
Dim userid As Integer
userid = dgvUserAccount.Item(0, dgvUserAccount.CurrentCell.RowIndex).Val…
con.Open()
sql = “DELETE FROM UserAccount WHERE UserId = ” & userid.ToString & “”
com = New SqlCommand(sql, con)
com.ExecuteNonQuery()
con.Close()
MessageBox.Show(“Record Deleted.”, “Operation Successful”, MessageBoxButtons.OK, MessageBoxIcon.Information)
populateDGV()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
con.Close()
End Try
End Sub
Private Sub btnCancel_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
btnAdd.Enabled = True
btnEdit.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
btnCancel.Enabled = False
disableTextboxes()
End Sub
Private Sub MProduct_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
populateDGV()
End Sub
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
Dim ds As New DataSet
sql = “SELECT * FROM [UserAccount] WHERE Username LIKE ‘%” & txtSearch.Text & “%’”
da = New SqlDataAdapter(sql, c

The SQL Statement will be like this:
sql = “UPDATE [UserAccount] SET [Field1] = ‘value1′, [Field2] = ‘value2′ …
WHERE [Your expression here]”
Did you notice that your WHERE clauses on your select and delete statements are not the same? One uses a LIKE and the other and “=”