473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Multiple primary keys with a datagrid?

Hi,

Maybe I'm missing something with the DataKeyField attribute of a datagrid
but it seems that it's somewhat limiting since this only allows you to
specify one field as the key.

I have a table that has two keys and it seems you need this value to find
the corresponding record in the DataSet in order to update the data from the
Datagrid.

Thanks for any ideas on this. Dave.
Nov 19 '05 #1
7 2439
I wonder why on earth you would ever want 2 PRIMARY keys in a DB. I
mean, how do you determine which field is valid now that either one
could be PRIMARY.

Primary keys should be and unless I'm wrong here, 99.99% of the time,
only 1 of them in a table.

Nov 19 '05 #2
Look at the 'Order Details' table in Northwind or 'titleauthor' table in Pubs
to see what I'm talking about.

The example I had in mind was if you have to update a quantity for an Order
Detail that was displayed in the a DataGrid since the table has multiple
columns identified as a primary key.

"-Karl" wrote:
I wonder why on earth you would ever want 2 PRIMARY keys in a DB. I
mean, how do you determine which field is valid now that either one
could be PRIMARY.

Primary keys should be and unless I'm wrong here, 99.99% of the time,
only 1 of them in a table.

Nov 19 '05 #3
Maybe Dave is using a wrong terminology and means that he has a table with a
composite Primary key consisting of 2 fields. That is totally valid on the
DB point of view and the combination of the 2 fields IS the primary key.

Also, Karl, primary keys are unique 100% of the time... if you think about
it, it would be scary if it was only 99.99 % of the time ;)

Hence the question of Dave is totally valid: how do you define a composite
primary key in the Datagrid DataKeyField property? Is it possible at all? If
not what is the best way?
I used to do stuff like having an invisible control in the row containing
the PK but I consider that as hacking and not a nice way to do it.
Maybe a smarter way is to have a serializable object that you store in the
viewstate of the DataGridItem (the row of the datagrid). But I never tried
it that way. Dave, if you try it like that, let me know if it works well.

Hope it helps,

Francois
"-Karl" <di*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I wonder why on earth you would ever want 2 PRIMARY keys in a DB. I
mean, how do you determine which field is valid now that either one
could be PRIMARY.

Primary keys should be and unless I'm wrong here, 99.99% of the time,
only 1 of them in a table.

Nov 19 '05 #4
That table is exactly an example where the primary key is a composite PK.

You can see on my other post in this thread for possible suggestions.

cheers,

Francois.
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Look at the 'Order Details' table in Northwind or 'titleauthor' table in Pubs to see what I'm talking about.

The example I had in mind was if you have to update a quantity for an Order Detail that was displayed in the a DataGrid since the table has multiple
columns identified as a primary key.

"-Karl" wrote:
I wonder why on earth you would ever want 2 PRIMARY keys in a DB. I
mean, how do you determine which field is valid now that either one
could be PRIMARY.

Primary keys should be and unless I'm wrong here, 99.99% of the time,
only 1 of them in a table.

Nov 19 '05 #5
Thanks for the feedback. You're right, I should have said "I have a table
that has two columns defined as the primary key".

Dave.

"Francois" wrote:
Maybe Dave is using a wrong terminology and means that he has a table with a
composite Primary key consisting of 2 fields. That is totally valid on the
DB point of view and the combination of the 2 fields IS the primary key.

Also, Karl, primary keys are unique 100% of the time... if you think about
it, it would be scary if it was only 99.99 % of the time ;)

Hence the question of Dave is totally valid: how do you define a composite
primary key in the Datagrid DataKeyField property? Is it possible at all? If
not what is the best way?
I used to do stuff like having an invisible control in the row containing
the PK but I consider that as hacking and not a nice way to do it.
Maybe a smarter way is to have a serializable object that you store in the
viewstate of the DataGridItem (the row of the datagrid). But I never tried
it that way. Dave, if you try it like that, let me know if it works well.

Hope it helps,

Francois
"-Karl" <di*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I wonder why on earth you would ever want 2 PRIMARY keys in a DB. I
mean, how do you determine which field is valid now that either one
could be PRIMARY.

Primary keys should be and unless I'm wrong here, 99.99% of the time,
only 1 of them in a table.


Nov 19 '05 #6
I'll have to see what you mean as I always understood DB's to be able
to have only 1 primary key to make sure there is absolutly no chance of
duplicates / data corruption.

what I meant by the 99.99% is that I was 99.99% sure that all db's
would have only 1 primary key.

I haven't touched upon composite PK so I do not know anything about
that terminology. Thanks for pointing it out. I'm just a noob :)

Nov 19 '05 #7
Ok, I am sorry for the 99.99 % thing, I misunderstood what u meant by that.

But an information that can be useful for you for later is that composite
primary key can be very useful for expressing a many to many relationships
between 2 tables.
Let's take a football (soccer if u are on the other side of the ocean)
example.
One league can have more than one team. But one team can belong to more than
one league. For example, the English Premier League (EPL) got obviously more
than one team. But one team can belong to more than one league as it could
belong for example to the EPL and the UEFA Champion's League.
But still you cannot permit that the same team / league combination appears
2 times in the DB as it would mean that one team appears 2 times in the same
league which obviously does not make sense. You then need to have a
composite Primary key to make that impossible to happen.

I hope that helps you understanding Composite PK. There are a lot of
litterature about it all over the internet if you want to see example and
all, it really worth it as you often need it in real world applications.

Cheers

Francois.

PS: By the way what does "noob" mean?
"-Karl" <di*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I'll have to see what you mean as I always understood DB's to be able
to have only 1 primary key to make sure there is absolutly no chance of
duplicates / data corruption.

what I meant by the 99.99% is that I was 99.99% sure that all db's
would have only 1 primary key.

I haven't touched upon composite PK so I do not know anything about
that terminology. Thanks for pointing it out. I'm just a noob :)

Nov 19 '05 #8

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

Similar topics

5
by: Bill | last post by:
I have a book cataloge where I have an author id linked up to the book. However, I'm finding that some books have mulitple authors, and I'm wondering if there is a way to add more than one id to...
26
by: pb648174 | last post by:
I have a table called BidItem which has another table called BidAddendum related to it by foreign key. I have another table called BidFolder which is related to both BidItem and BidAddendum, based...
3
by: gregory.sharrow | last post by:
I need to secure a datawarehouse table at the row level based on 1 to many keys on that table. A user should only see the rows they have access to. I need to be able to figure out which rows they...
3
by: Ryan Riddell | last post by:
I am using the DataGrid control from 4guys (http://aspnet.4guysfromrolla.com/demos/RowHighlighter.aspx). I want to display 2 columns and allow editing. The only column I want the user to be able to...
1
by: Nita Raju | last post by:
Hi, I'm trying to build a datagrid that gets rows heading from records in one table, columns heading from records in another table, and cell values from records in a third table that maps the...
2
by: Sam | last post by:
Hi all I have a database table that has multiple column primary key and every thing looks fine when I load it in the datagrid web control. The problem is that the datagrid web control can only...
1
by: CharChabil | last post by:
Hey guys Using Sql/express Table 1 : I set 3 fields to be primary keys for Table1 (i have just marked each field with a key (primary key)(is there anything else to do)? Table 2 : I should...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
13
by: Eric IsWhoIAm | last post by:
I have four tables created so far: Courses, Instructors, Courses and Instructors (which shows the Course and Instructor Name fields, but holds their IDs since those are the keys), and Students....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...
0
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...

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.