Vb.net get primary key after inserting row in table adapter

1.8k views Asked by At

Ok, I'm trying to simply add a new record to an access database in vb.net (ole.db). I have a dataset and I have configured the data table.

After adding a row like this:

    Dim newRow As dataSet.MealsRow = dataSet.Meals.NewMealsRow
    newRow.mealName = "name"
    newRow.mealType = 12
    dataSet.Meals.AddMealsRow(newRow)
    tableAdapter.Update(dataSet.Meals)
    Dim tableId As Integer = newRow.Id

The tableId is always returing an incorrect primary key value. If I leave the AutoIncrementSeed to -1 and AutoIncrementStep to -1 in the Data Table, then the tableId will have negative values starting from -1 and going down, -2, -3, etc...

Shouldn't it picking up the correct key value inserted there ?

0

There are 0 answers