CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    34

    DataColumn question

    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?

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: DataColumn question

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured