insert data into Access database (could it be AutoNumber?)

  • Thread starter Thread starter Scott Starker
  • Start date Start date
S

Scott Starker

This is a question from a Newbie. Although it executes correctly there is no
new record added to the table (which isn't what I want :). Could it be that
the table has an "AutoNumber" field (RecordID)? I have tried (among other
things):
SQLString = "SELECT * FROM TypeNames"
DBAdapter2 = New OleDbDataAdapter(SQLString, DBConnection)
DBDataSet2 = New DataSet()
DBAdapter2.Fill(DBDataSet2, "TypeNames")
DBTable3 = DBDataSet2.Tables("TypeNames")
foundRow2 = DBTable3.NewRow()
foundRow2("TypeCode") = cmbTypeLookup.Text
foundRow2("TypeDomain") = txtDomain.Text
foundRow2("TypeNameSpan") = txtTypeName.Text
' New row.
DBTable3.Rows.Add(FoundRow2)

I assume that the "AutoNumber" would get inserted automatically but I may be
wrong. Could that be it? How do I do this? Thanks.

Scott
 
¤ This is a question from a Newbie. Although it executes correctly there is no
¤ new record added to the table (which isn't what I want :). Could it be that
¤ the table has an "AutoNumber" field (RecordID)? I have tried (among other
¤ things):
¤ SQLString = "SELECT * FROM TypeNames"
¤ DBAdapter2 = New OleDbDataAdapter(SQLString, DBConnection)
¤ DBDataSet2 = New DataSet()
¤ DBAdapter2.Fill(DBDataSet2, "TypeNames")
¤ DBTable3 = DBDataSet2.Tables("TypeNames")
¤ foundRow2 = DBTable3.NewRow()
¤ foundRow2("TypeCode") = cmbTypeLookup.Text
¤ foundRow2("TypeDomain") = txtDomain.Text
¤ foundRow2("TypeNameSpan") = txtTypeName.Text
¤ ' New row.
¤ DBTable3.Rows.Add(FoundRow2)
¤
¤ I assume that the "AutoNumber" would get inserted automatically but I may be
¤ wrong. Could that be it? How do I do this? Thanks.

Are you calling the Update method for the DataAdapter somewhere in your code?


Paul
~~~~
Microsoft MVP (Visual Basic)
 
As you suggested I used
DBAdapter2.Update(DBDataSet2, "TypeNames")
at the end of this code and it gave me
"Update requires a valid InsertCommand when passed DataRow collection with
new rows."

I thought "InsertCommand" was for another way to insert a row...

Scott
 
¤ As you suggested I used
¤ DBAdapter2.Update(DBDataSet2, "TypeNames")
¤ at the end of this code and it gave me
¤ "Update requires a valid InsertCommand when passed DataRow collection with
¤ new rows."
¤
¤ I thought "InsertCommand" was for another way to insert a row...

No, it's what the DataAdapter uses to perform the INSERT operation. You've already created the
SelectCommand, which was generated when you instantiated the DataAdapter with your SQLString, but
you also need to assign an InsertCommand value if you're going to perform this operation as well.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top