DataGrid

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

thanks




 




svariaAsked:
Who is Participating?
 
jellis613Commented:
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
0
 
svariaAuthor Commented:
Great Tip.
Thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.