Adding a record to a Microsoft Jet database

  • Thread starter Barbara Pickerd
  • Start date
B

Barbara Pickerd

I’m a beginner.
I want to add a new record to my table; however I get an error:

“An unhandled exception of type 'System.InvalidOperationException'
occurred in system.data.dll

Additional information: Dynamic SQL generation is not supported against
a SelectCommand that does not return any base table information.”

Here is my code:

Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDataAdapter As New OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
'Private m_Insert As OleDb.OleDb.OleDbInsertCommand1
Private m_dtContacts As New DataTable
'Private m_dtContacts As New DataTable
Private m_rowPosition As Integer = 0


Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles btnAddNew.Click

Dim drNewRow As DataRow = m_dtContacts.NewRow
drNewRow("Number") = TxtAddNumber.Text
drNewRow("First") = txtAddFirst.Text
drNewRow("Last") = txtAddLast.Text
drNewRow("Status") = TxtAddStatus.Text

m_dtContacts.Rows.Add(drNewRow)

m_daDataAdapter.Update(m_dtContacts)
m_rowPosition = m_dtContacts.Rows.Count - 1
Me.ShowCurrentRecord()

End Sub
 
W

William Ryan eMVP

It looks like you probably don't have a Primary Key on the table, can you
verify this and we'll take it from there.
 
B

Barbara Pickerd

I replied to this message earlier; however I don’t see my submission, so
I’m posting it again.

Number is my primary key
Thank you for your help.

Barbara Pickerd

I'm a beginner.
 
W

William Ryan eMVP

Barbara:

It also looks like the CommandBuilder is never being linked to the
DataAdatper and/or the dataadatper doesn't have a valid Update statement of
its own. Does it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top