Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView Not Updating

$
0
0

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.  I'm 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


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>