jeudi 1 septembre 2016

updating column/s in access db after getting which DataGridView CheckBoxes are selected in vb.net

I am just starting in vb.net and am trying to update a row in access db that is selected by a DataGridView checkbox in vb. net

here is a part of the system

here is my code:

Private Sub editIO_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles editIO.LinkClicked

        If myConnection.State = ConnectionState.Open Then
            myConnection.Close()
        End If
        myConnection.ConnectionString = connString
        myConnection.Open()


        If editIO.Text = "Enable Time In/Out Edit" Then
            Try
                Dim CheckedRows =
                    (
                        From Rows In AdminTabDisplay.Rows.Cast(Of DataGridViewRow)()
                        Where CBool(Rows.Cells("ck").Value) = True
                    ).ToList
                If CheckedRows.Count > 0 Then

                    Dim sb As New System.Text.StringBuilder
                    For Each row As DataGridViewRow In CheckedRows
                        sb.AppendLine(row.Cells("Last Name").Value.ToString)

                    Next
                    Dim cmd As OleDbCommand = New OleDbCommand("UPDATE [Roster1] SET [EditTime] = 'e' WHERE [Last Name] = '" & sb.ToString & "'", myConnection)
                    Dim dr As OleDbDataReader = cmd.ExecuteReader




                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        viewAdmin()
        editIO.Text = "Disable Time In/Out Edit"
    End Sub

It can check which checkboxes are selected and can update the whole database when the link is clicked. But every time I add a "WHERE" clause after db command (Which is "WHERE [Last Name] = '" & sb.ToString & "'"), It doesnt update the selected row.

Also, I would like to use the "Employee ID" column in replacement of the "Last Name" column used in the WHERE clause

If possible, please explain it as simple as can be. I'm still a beginner in VB.net.Thank you very much! Every help is much appreciated!




Aucun commentaire:

Enregistrer un commentaire