Ok here's my problem, I cannot figure it out, and I'm sure this has been addressed several times, but I am desperate so please bear with me. I make changes to my datatable, but it doesn't commit back to the original file it reads from even with AcceptChanges(). Here's the relevent code.
Private m_dtInputDataTable As New DataTable
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDataAdapter As New OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
m_cnADONetConnection.ConnectionString() = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\SperryMarineData.mdb"
m_cnADONetConnection.Open()
m_daDataAdapter = _
New OleDb.OleDbDataAdapter("SELECT * FROM InputDataTable", m_cnADONetConnection)
m_dtInputDataTable.Clear()
m_daDataAdapter.Fill(m_dtInputDataTable)
If m_dtInputDataTable.Rows.Count <> 0 Then
If lstvJobQueue.SelectedIndices.Count > 0 Then
m_Item = lstvJobQueue.SelectedItems(0).Text()
For m_rowPosition = 0 To m_dtInputDataTable.Rows.Count - 1 Step 1
If m_dtInputDataTable.Rows(m_rowPosition)("Job ID Number") = m_Item Then
If m_dtInputDataTable.Rows.Count <> 0 Then
m_dtInputDataTable.Rows(m_rowPosition).Delete()
End If
End If
Next
Else
MessageBox.Show("Please select a job to delete.", "No Job Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Else
MessageBox.Show("There is no job to delete.", "No Job", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
m_dtInputDataTable.AcceptChanges()
m_daDataAdapter.Update(m_dtInputDataTable)
If i place m_dtInputDataTable.AcceptChanges() after m_daDataAdapter.Update(m_dtInputDataTable) I get an
Unhandled Exception of Type 'System.Data.Oledb.OledbException' occured in system.data.dll
I honestly can't figure this out. This is the only thing i need to finish my Senior design project. I had to teach myself VB.net for this.
Private m_dtInputDataTable As New DataTable
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDataAdapter As New OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
m_cnADONetConnection.ConnectionString() = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\SperryMarineData.mdb"
m_cnADONetConnection.Open()
m_daDataAdapter = _
New OleDb.OleDbDataAdapter("SELECT * FROM InputDataTable", m_cnADONetConnection)
m_dtInputDataTable.Clear()
m_daDataAdapter.Fill(m_dtInputDataTable)
If m_dtInputDataTable.Rows.Count <> 0 Then
If lstvJobQueue.SelectedIndices.Count > 0 Then
m_Item = lstvJobQueue.SelectedItems(0).Text()
For m_rowPosition = 0 To m_dtInputDataTable.Rows.Count - 1 Step 1
If m_dtInputDataTable.Rows(m_rowPosition)("Job ID Number") = m_Item Then
If m_dtInputDataTable.Rows.Count <> 0 Then
m_dtInputDataTable.Rows(m_rowPosition).Delete()
End If
End If
Next
Else
MessageBox.Show("Please select a job to delete.", "No Job Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Else
MessageBox.Show("There is no job to delete.", "No Job", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
m_dtInputDataTable.AcceptChanges()
m_daDataAdapter.Update(m_dtInputDataTable)
If i place m_dtInputDataTable.AcceptChanges() after m_daDataAdapter.Update(m_dtInputDataTable) I get an
Unhandled Exception of Type 'System.Data.Oledb.OledbException' occured in system.data.dll
I honestly can't figure this out. This is the only thing i need to finish my Senior design project. I had to teach myself VB.net for this.