primary key problem

I

Irfan

hi,

when i add a row in a table of a dataset (using dt.rows.add), i expect the
primary key value to be gernarated automatically as i have set it to
Autonumber in access. But instead of generating autonumber, it does not do
anything, which results in null value in the primary key col of new row.

Although remedy to the above is, not to include the primary key in the
selectCommand so that Access does it itself. But i need to include the
primary key in the table because i have to set parent - child relationalship
with another table.

Could someone advise please how can the primarykey of a table in a dataset
to be populated by a unique identifier and not by a null value.

TIA
Irfan
 
I

Irfan

Cor,

It is an existing database in MS Access, the tables are already created in
the actual database and now i have transferred them to into dataset.



irfan
 
P

Paul Clement

¤ hi,
¤
¤ when i add a row in a table of a dataset (using dt.rows.add), i expect the
¤ primary key value to be gernarated automatically as i have set it to
¤ Autonumber in access. But instead of generating autonumber, it does not do
¤ anything, which results in null value in the primary key col of new row.
¤
¤ Although remedy to the above is, not to include the primary key in the
¤ selectCommand so that Access does it itself. But i need to include the
¤ primary key in the table because i have to set parent - child relationalship
¤ with another table.
¤
¤ Could someone advise please how can the primarykey of a table in a dataset
¤ to be populated by a unique identifier and not by a null value.

See the following:

HOW TO: Retrieve the Identity Value While Inserting Records into Access Database By Using Visual
Basic .NET
http://support.microsoft.com/kb/815629/EN-US/


Paul
~~~~
Microsoft MVP (Visual Basic)
 
I

Irfan

This is what i am doing to add a new row,

Dim dr As DataRow = dtComboBoxdata.NewRow
'set all columns
dr("ElementName") = EleName
dr("lineloadIDfk") = lineID
dr("fileIDfk") = fileID
dtComboBoxdata.Rows.Add(dr)
da.Update(ds, "comboBoxdata")
 
C

Cor Ligthert

Irfan,

I am not sure anymore of the missingscheme method helps this, you can try
it.

http://msdn.microsoft.com/library/d...ndataadapterclassmissingschemaactiontopic.asp

My idea was not and than you have to add the autoincrement properties.
http://msdn.microsoft.com/library/d...tml/frlrfsystemdatadatacolumnmemberstopic.asp

If you have this in a parentchildrelation this is AFAIK a hell of a job,
because the identifiere in the dataset is not the original one, however a
substitute. The original one is given at the insert time (and than you can
find the value of the indentifier as is described at @@Identity in Pauls
link). I would in this case first create the identifier and than add the
childs.

HoweverI prefer to use a Guid as the uniqueidentifier.

http://msdn.microsoft.com/library/d...n-us/cpref/html/frlrfsystemguidclasstopic.asp

Probably do you have a now a long road to go.

I hope this helps something.

Cor
 
I

Irfan

thanks, Cor, seems there is not a short cut.

I will go through the links, thanks again
irfan
 

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