• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

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




 




0
svaria
Asked:
svaria
1 Solution
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now