Composite DatakeyField?

  • Thread starter Thread starter William Ryan eMVP
  • Start date Start date
W

William Ryan eMVP

Ismail:

How are you buiding the key? A really easy way to do this that comes to
mind is create an expression column with all three values (after all, three
fields can make a key but how would they be formatted?) and bind to that
column. If you could tell me a little more about the key and what you want
displayed, I may be able to be more helpful.

Cheers,

Bill
 
P.S. Please check your clock!
William Ryan eMVP said:
Ismail:

How are you buiding the key? A really easy way to do this that comes to
mind is create an expression column with all three values (after all, three
fields can make a key but how would they be formatted?) and bind to that
column. If you could tell me a little more about the key and what you want
displayed, I may be able to be more helpful.

Cheers,

Bill
 
Ismail:

I undestand the concept of a composite key ;-). However, what I'm wondering
is in your listbox, are categoryID and ProductID supposed to be displayed
as an atomic unit or are you going to have a separator in therm ie

001001
001002
002001
or are they going to have some sort of format specifyer
001-001
001-002
002-001

In addition, where are the keys defined on the database side or the
datatable (local side)? Either way, I think the solution is to create an
expression colum comprised of both of them naming your expression colum
CompositeKey for instance. Bind the listbox and set it's DisplayMember
(DataTextField in ASP.NET) to CompositeKey and set its ValueMember
(DataValueField in ASP.NET) to whatever the field you want updated is. Also,
make sure you set the Column's unique property to true which will provide
the functionailty of a true PK.

HTH,

Bill
 
Is there any option we can use Composite DataKeyField in the DataList and
DataGrid?
 
Create a new column then and set it to "FirstColumn + ' - ' + SecondColumn'
for instance if you want a hyphen seperating it visually. This will be your
displaymember or DataTextField...and set the other one to your
DataValueField...
 
As Composite Key concept says that there can
be more than one primary keys in a database table .

I want two different columns to store two primary keys and both of them make
composite key in my database

here we can have only one key
Dim productID As String =
MyDataList.DataKeys(MyDataList.SelectedItem.ItemIndex)


CategoryID and ProductID together make composite key in my database.I faced
this problem when updating database record having composite key ,

i give you more detail
catid = 001 prodid =001
catid = 001 prodid =002
catid=002 prodid =001

If you look in primary keys , records are repeating but as composite they
are not .

if i update record with prodid then i will have two records updated .
 
Thanks , Keys are Defined in database side and then called to Bind in
DataList so i got ProductID in one column of List and CategoryID in another
, But i think i am getting the point now .
 
Back
Top