Click to See Complete Forum and Search --> : DataColumn question


beeper
March 15th, 2005, 07:28 AM
I have DataTable

DataTable dt=ds.Tables["Persons"];

____________________
LP.| FName | SName |
-----------------------
21 John | Smith |
33 Ted | Bear |
54 Michael | Zxxx |
[...]
132 Stif | Som |
____________________


I add a new column to this table

DataColumn colPosition=new DataColumn("Position");
dt.Columns.Add(colPosition);

How fill this data column a data beetwen 0 to number of records

__________________________
LP.| FName | SName | Position
------------------------------
21 John | Smith | 0
33 Ted | Bear | 1
54 Michael | Zxxx | 2
[...]
132 Stif | Som | 124
___________________________


DataRow dr=dt.NewRow();
dr["Position"]="1";
dt.Rows.Add(dr);

this add a new row, but i wont to update existing table in Position colum and add a number to them.



How do that?

jhammer
March 15th, 2005, 08:09 AM
If i understood your question correctly you should use:

for (int i=0; i<ds.Tables["YourTable"].Rows.Count ; i++)
ds.Tables["YourTable"].Rows[i]["Position"] = i;

where YourTable is the name of your table (didn't remeber it)