Newrow in dataset with primary key set by database

G

Guest

Okay, I am doing the:
table.rows.add(NewRow)

thing, but now I decide I want to be able to find the row by primary key. Now the primary key for this table is an Ident, so that value will come from the database. I have all my update components in order. Every thing works, until of course I set the primary key on the datatable (in a dataset). Now I can't add a row unless I set the ident column, but I can't do that cause it comes from the database. Any ideas?
 
W

William Ryan eMVP

Check out Bill Vaughn's Managing and @@Identity Crisis at www.betav.com ->
Articles ->MSDN

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
M K said:
Okay, I am doing the:
table.rows.add(NewRow)

thing, but now I decide I want to be able to find the row by primary key.
Now the primary key for this table is an Ident, so that value will come from
the database. I have all my update components in order. Every thing works,
until of course I set the primary key on the datatable (in a dataset). Now I
can't add a row unless I set the ident column, but I can't do that cause it
comes from the database. Any ideas?
 
K

Kevin Yu [MSFT]

Hi Mark,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add rows with identity
column in a DataTable. If there is any misunderstanding, please feel free
to let me know.

Generally, when you are using an auto increment column as primary key, we
set the both the auto-increment seed and step to -1. For more information,
please check the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/ht
ml/manidcrisis.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Okay, here's the deal. I get some values that need to be placed in my new datarow.
drNew = dataset.tables("dataTable").newrow
drNew("Field1") = var1
drNew("Field2") = var2
dataset.tables("dataTable").rows.add(drNew)

If dataset.haschanges then
Dim drChanges as new dataset
drChanges = dataset.getChanges
primaryKey = dataAccessComp.setChanges(drChanges)
end if
 

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