Expand|Select|Wrap|Line Numbers
- Private Function LoadTableData() As Boolean
- Try
- Dim cmd As New OleDb.OleDbCommand("SELECT * FROM " & cmbTables.Text, c)
- ' Dim ds As New DataSet
- Dim dt As New DataTable
- Dim da As New OleDb.OleDbDataAdapter(cmd)
- dt.TableName = cmbTables.Text
- ds.Tables.Add(dt)
- c.Open()
- da.Fill(ds, cmbTables.Text)
- Dim cb As New OleDb.OleDbCommandBuilder(da)
- da.InsertCommand = cb.GetInsertCommand()
- da.UpdateCommand = cb.GetUpdateCommand()
- da.DeleteCommand = cb.GetDeleteCommand()
- c.Close()
- Me.MachinesBindingSource.DataSource = ds
- Me.MachinesBindingSource.DataMember = cmbTables.Text
- Me.DataGridView1.AutoGenerateColumns = True
- ' Me.DataGridView1.ReadOnly = True
- Return True
- Catch ex As Exception
- MsgBox(Err.Description)
- Return False
- End Try
- End Function
This is the code I have in my "save" button click:
Expand|Select|Wrap|Line Numbers
- If txtReason.Text <> "" Then
- 'write change to database
- ' MsgBox(strCurrentUser & " changed column " & ColumnThatWasChanged & " for record " & DataGridView1.Rows(CurrentRow).Cells(0).Value.ToString() & " in table " & cmbTables.Text & " from " & PreviousValue & " to " & NewValue)
- Dim da As New OleDb.OleDbDataAdapter
- Dim cmd As New Data.OleDb.OleDbCommand
- If ds.HasChanges() Then
- c.Open()
- Me.Validate()
- Me.MachinesBindingSource.EndEdit()
- da.Update(ds, cmbTables.Text)
- 'da.Update(ds, cmbTables.Text)
- c.Close()
- End If
- Else
- MsgBox("You must enter a reason for the change.")
- End If
Thanks,
Jason