DataGridView Not Updating

  • Thread starter Thread starter ericvanburen
  • Start date Start date
E

ericvanburen

Guest
Hi - I have a simple DataGridview with 3 columns - ID (PK), Email, PCA. I want the user to able to update both the Email and PCA fields. Im not throwing any errors but the fields are not updating in my database. Thanks for any help.

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
cnnOLEDB.ConnectionString = strConnectionString
cnnOLEDB.Open()

Dim rowIndex As Integer
Dim ID As Integer
Dim strEmail As String
Dim strPCA As String

rowIndex = DataGridView1.CurrentRow.Index
ID = DataGridView1.Item(0, rowIndex).Value
strEmail = DataGridView1.Item(1, rowIndex).Value.ToString()
strPCA = DataGridView1.Item(2, rowIndex).Value.ToString()

Dim strSQL As String = "UPDATE PCAEmailLists SET Email=" & strEmail & ", PCA=" & strPCA & " WHERE ID = " & ID & ""
Dim cmd As New OleDbCommand

Try
With cmd
.CommandText = strSQL
.Connection = cnnOLEDB
.ExecuteNonQuery()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnnOLEDB.Close()
End Try
End Sub

Continue reading...
 
Back
Top