Composite DataKeyField?

Discussion in 'ASP .Net' started by Felbrigg, Feb 9, 2004.

  1. Felbrigg

    Felbrigg Guest

    Are your strying to store more than one item of data in an item?


    "Ismail Rajput" <> wrote in message
    news:%...
    > Is there any option we can use Composite DataKeyField in the DataList and
    > DataGrid?
    >
    >
     
    Felbrigg, Feb 9, 2004
    #1
    1. Advertising

  2. Is there any option we can use Composite DataKeyField in the DataList and
    DataGrid?
     
    Ismail Rajput, Feb 10, 2004
    #2
    1. Advertising

  3. Ismail,
    If I understand correctly,you need to use a DataKeyField with both catid
    and prodid information.
    This may not be the straight forward way but here is how you can do this.
    In your sql concatenate two of these columns which you want as composite
    key separated by a charater say /.
    For eg: in SQL Server
    Select (catid + '/' + prodid) as catid_prodid,..........from
    table_name
    Set the DataKeyField as catid_prodid and do a split
    to separate them before you make your UPDATE statement.
    string[] compositecols=cateidprodid.Split('/');
    compositecols[0] and compositecols[1] will have catid and prodid
    respectively.
    There might be some other way which I am not sure.
    Hope this helps.
    Regards,
    Marshal Antony
    ..NET Developer
    http://www.dotnetmarshal.com


    "Ismail Rajput" <> wrote in message
    news:...
    > 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 .
    >
    > "Felbrigg" <> wrote in message
    > news:...
    > > Are your strying to store more than one item of data in an item?
    > >
    > >
    > > "Ismail Rajput" <> wrote in message
    > > news:%...
    > > > Is there any option we can use Composite DataKeyField in the DataList

    > and
    > > > DataGrid?
    > > >
    > > >

    > >
    > >

    >
    >
     
    Marshal Antony, Feb 10, 2004
    #3
  4. 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 .

    "Felbrigg" <> wrote in message
    news:...
    > Are your strying to store more than one item of data in an item?
    >
    >
    > "Ismail Rajput" <> wrote in message
    > news:%...
    > > Is there any option we can use Composite DataKeyField in the DataList

    and
    > > DataGrid?
    > >
    > >

    >
    >
     
    Ismail Rajput, Feb 10, 2004
    #4
  5. Marshal ,

    Thanks and yes you got correctly as i wanted it to be understood
    ..I think this is the best possible way ,the way you told me to do this.


    "Marshal Antony" <> wrote in message
    news:...
    > Ismail,
    > If I understand correctly,you need to use a DataKeyField with both

    catid
    > and prodid information.
    > This may not be the straight forward way but here is how you can do this.
    > In your sql concatenate two of these columns which you want as composite
    > key separated by a charater say /.
    > For eg: in SQL Server
    > Select (catid + '/' + prodid) as catid_prodid,..........from
    > table_name
    > Set the DataKeyField as catid_prodid and do a

    split
    > to separate them before you make your UPDATE statement.
    > string[] compositecols=cateidprodid.Split('/');
    > compositecols[0] and compositecols[1] will have catid and prodid
    > respectively.
    > There might be some other way which I am not sure.
    > Hope this helps.
    > Regards,
    > Marshal Antony
    > .NET Developer
    > http://www.dotnetmarshal.com
    >
    >
    > "Ismail Rajput" <> wrote in message
    > news:...
    > > 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 .
    > >
    > > "Felbrigg" <> wrote in message
    > > news:...
    > > > Are your strying to store more than one item of data in an item?
    > > >
    > > >
    > > > "Ismail Rajput" <> wrote in message
    > > > news:%...
    > > > > Is there any option we can use Composite DataKeyField in the

    DataList
    > > and
    > > > > DataGrid?
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ismail Rajput, Feb 11, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sramruttun
    Replies:
    0
    Views:
    350
    sramruttun
    Jul 10, 2003
  2. Beryl Small

    DatakeyField with multi-column primary key

    Beryl Small, Mar 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    444
    Beryl Small
    Mar 1, 2004
  3. Homer J. Simpson
    Replies:
    2
    Views:
    1,120
    Suresh
    Mar 5, 2004
  4. Adam Knight

    DataGrid - DataKeyField!!

    Adam Knight, Aug 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    4,211
    Adam Knight
    Aug 7, 2005
  5. sramruttun

    datakeyfield and 3 fields making up the PK

    sramruttun, Jul 10, 2003, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    171
    sramruttun
    Jul 14, 2003
Loading...

Share This Page