Posted on 2005-04-15
Last Modified: 2010-04-07
I am trying to update using data grid
my database table has composite key (2 columns as primary key).

Table (lineNo,date,rate,crew)
lineNo and date are primary keys.

I got the datagrid to display the data

lineNo  date               rate               crew
10        4/1/05           100               5
20        4/2/05           120               6
10        4/6/05           110               4

I want the user to be able to change date,rate and crew using data grid. (date column is the part of primary key)

Please help



Question by:svaria
    LVL 2

    Accepted Solution

    why dont you try this:
    1) add an an autoincrement int identity row for the table. This gives the table one column that is a primary key for that table.
    2) In your select statement/stored to retrieve the data, include the identity row. (If you are using auto-generate columns for the datagrid, you will need to make this false, and code your own column templates to get this to work - otherwise the identity column data will be printed in the datagrid)
    3) Set the DataKeyField for the DataGrid table to be the new Identity column
    4) When you are coding the EditCommand event function for the datagrid, you can retrieve the datakey for the row using the following:
    int key = Convert.ToInt32(datagrid1.DataKeys[e.Item.ItemIndex]);
    You should then be able to use this key in the WHERE clause of your SQL statement to update the data

    Author Comment

    Great Tip.
    Thanks a lot.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now