473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2468
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.goo glegroups.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**@discussio ns.microsoft.co m> wrote in message
news:62******** *************** ***********@mic rosoft.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.goo glegroups.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.goo glegroups.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
3371
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 the author id field. Or do I have to have many author id fields? Any way around that? Thanks, Bill *** Sent via Developersdex http://www.developersdex.com ***
26
14147
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 on a column called RefId and one called Type, i.e. type 1 is a relationship to BidItem and type 2 is a relationship to BidAddendum. Is there any way to specify a foreign key that will allow for the different types indicating which table the...
3
2549
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 have access to using a single sql statement and it cannot be dynamic SQL or a stored procedure (this is a limitation based on the reporting tool we use). The conditions can be any combination of "and" and "or" operators. I have seen posts (and...
3
2378
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 change is the second column. I made this work via ReadOnly="true" for the first column. The second requirement is that the grid stores 2 table primary key values in columns 3 and 4. These columns will mean nothing to the user and could...
1
1422
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 first and second to the cell value. The primary keys of the first two tables are foreign keys in the third table. Any help would be greatly appreciated.
2
3462
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 take one single field to be its DataKeyField while my data table has multiple(2) column primary. Is there a way to create a datagrid web control's DataKeyField which can take a multiple columns. Thank you
1
3415
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 add a foreign key for this table linked to the 3 primary keys of table1 Can this be done /how? Any hint for that?
11
3684
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) and the 'employee name'. There is another table which assigns an ID to the Shifts, i.e. 1,2 and 3 for morn, eve & night shifts respectively. From the mother table, the incentive is calculated datewise for each employee as per his shift duty. In...
13
3792
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. Now, I wish to create a Classrooms (or something similar) table which will allow me to pick the Course from Courses and Instructors, and hold multiple Students for each Course. I am unsure how to do this in Access. Each student can have multiple...
0
9522
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,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7543
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
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
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.