Getting IDs for newinserted rows
Hello!
I insert some new rows into a DataTable and then insert the rows into the database via
Code:
changes = dataTable.GetChanges();
if (changes != null)
{ int nRowsUpdated = dataAdapter.Update(changes);
}
This works fine. But now I need to know to values of the "auto_incremet primary key" the database gave to this new rows. So how can I get the ids of the records I just inserted?
Re: Getting IDs for newinserted rows
Re: Getting IDs for newinserted rows
Re: Getting IDs for newinserted rows
Quote:
Originally Posted by martho
Hello!
I insert some new rows into a DataTable and then insert the rows into the database via
Code:
changes = dataTable.GetChanges();
if (changes != null)
{ int nRowsUpdated = dataAdapter.Update(changes);
}
This works fine. But now I need to know to values of the "auto_incremet primary key" the database gave to this new rows. So how can I get the ids of the records I just inserted?
call this instead:
int nRowsUpdated = dataAdapter.Update(datatable);
and note how your id fields are all now popualted. magic