473,658 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

primary key problem

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

Nov 21 '05 #1
6 1314
Irfan,

Is that table in an existing database or is it a new database?

Cor
Nov 21 '05 #2
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

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Irfan,

Is that table in an existing database or is it a new database?

Cor

Nov 21 '05 #3
On Tue, 21 Jun 2005 17:22:39 +0100, "Irfan" <ir***@asc-ltd.co.uk> wrote:

¤ 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)
Nov 21 '05 #4

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

Dim dr As DataRow = dtComboBoxdata. NewRow
'set all columns
dr("ElementName ") = EleName
dr("lineloadIDf k") = lineID
dr("fileIDfk") = fileID
dtComboBoxdata. Rows.Add(dr)
da.Update(ds, "comboBoxda ta")

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Irfan,

Is that table in an existing database or is it a new database?

Cor

Nov 21 '05 #5
Irfan,

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

http://msdn.microsoft.com/library/de...ctiontopic.asp

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

If you have this in a parentchildrela tion 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 uniqueidentifie r.

http://msdn.microsoft.com/library/de...classtopic.asp

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

I hope this helps something.

Cor


Nov 21 '05 #6
thanks, Cor, seems there is not a short cut.

I will go through the links, thanks again
irfan
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:e6******** ******@TK2MSFTN GP12.phx.gbl...
Irfan,

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

http://msdn.microsoft.com/library/de...ctiontopic.asp

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

If you have this in a parentchildrela tion 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 uniqueidentifie r.

http://msdn.microsoft.com/library/de...classtopic.asp

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

I hope this helps something.

Cor

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3701
by: Ghulam Farid | last post by:
Hi i have a table with primary key defined on col1 and col2. now i want to have col3 also included in primary key. when i alter the table it gives me error for duplicate rows. there is an option for 'with nocheck' but it only works with check or foreign key constraint. is there any option in sql server like in oracle 'no validate' which doesnt validate the existing data and force the data validation from new records. thanx Farid
1
1209
by: dev | last post by:
Hej There. We have a big problem. We have now for 4th years had a SQL Server without problems. But sutnely some of the primary keys are deleted. The subdata to the primary keys are not deleted. This is a big problem because This is a billing system. Recently there was over 300 primay keys deleted. Good that we have backup but still... NOOOT good Can anyone help me to solve this problem!!! PLEASE
9
6857
by: 101 | last post by:
Taking a course on SQL. They are saying you can get better performance by having multiple files for a group. They then graphically show an example of "Primary" with multiple data files. I have tried altering PRIMARY to have multiple data files and I get and error. I have tried creating a new database with multiple PRIMARY files and get an error. I can ALTER and CREATE secondary files with multiple data files with no
7
2950
by: Ilan Sebba | last post by:
I am trying to add a record using SQL. My problem is that the primary keys are foreign keys, and these foreign keys are autonumbers. I therefore do not know the primary keys of the record I am trying to insert. I therefore do not think that I can use the sql "Insert Into" command. Here is a simplified illustration of my tables: tblFather NaturalKey1 NatuarlKey2
7
5343
by: Philip | last post by:
Hey all, (Access 2000) I've been having a horror story with this design problem. My Database is Structured like This: AUTHORS, BOOKS, PAGES. Those are the Tables and each Item in each table needs a unique ID# based on its context. Primary Keys AUTHORS = AuthorID - NO Duplicates
2
3229
by: stranger | last post by:
My database is set up so people can input parts orders. Sometimes they order the same parts on a monthly basis. I want to be able to duplicate past parts orders and have it pasted in with a new primary key. My first attempt seemed to work(minus a few Microsoft glitches). I used a "duplicate" command button at first. This made a copy of the record but failed to bump up the primary key by 1 number(so it seemed). Actually, the number did...
1
3821
by: | last post by:
Hi, I am getting the following error when I run my Visual Basic application: "Cannot add primary key constraint since primary key is already set for the table" I am using datasets with primary keys which are filled from an SQL Server database. These datasets were automatically
3
3218
by: Hugh O | last post by:
Hi, I am not sure if this type of question should be raised in this Newsgroup. If not please direct me. I am new to using RDO.Net data access but I thought I understood it. The 6 lines of code below is simply trying to load an empty table that has only three columns. In the code I set the Name and Type fields. The third column is a unique primary key set to Integer. I have set the Primary Key to Identity with a seed of 1 and...
8
3266
by: shumaker | last post by:
I'm wondering if adding an autonumber primary key will improve the performance of a multiuser access database on a network share. I have a website that lists many tips for improving performance of access, but doesn't mention primary keys. However, it seems logical to think that having no primary key means that when a user updates a record, the database has to do comparisons on multiple fields to identify the specific record being...
9
3904
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for eg: area.txt, school.txt, students.txt.... and so on (ok?!?) now, 1. area code used in the school.txt must be defined in the area.txt (Primary key in area => area_code defined in area.txt & Foreign key on school => area_code defined in...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.