Finding the index of the DataRow to update?

Discussion in 'ASP .Net' started by Doug, Dec 2, 2003.

  1. Doug

    Doug Guest

    I've got a strongly-typed dataset with 2 related tables in it ("Staff"
    and "Roles"). I want to make a change to the parent Staff row and also
    to its child Role row. I'm having difficulty figuring out the best way
    to do this.

    First question:
    I can get myself a new instance of a row and make changes to it, but
    presumably that's then a separate object from the original dataset
    row. How do I reconcile my changes back to the dataset?

    Second question:
    Because I haven't figured out the answer to the above, I'm updating
    the rows directly in the dataset. But in order to find which row to
    update, I'm having to do something which looks really complicated (see
    code snippet below).

    It can't be that difficult! But the MSDN examples are no help at all -
    they simply refer to the required row using an absolute value:
    dataset1.Tables["Customers"].Rows[4]["CompanyName"] = "Wingtip Toys";
    How much use is that in The Real World?! Not much - what I need to
    know is, how to dynamically find that value 4 in the example.

    Any help would be much appreciated. Thanks very much. Here's the code
    snippet:

    //find the index of the Staff row to update (where StaffID=_staffID):
    UserDataSet.StaffRow[] staffRows=this.GetStaffRowsxMany();
    int i=0, rowID=0;
    foreach(UserDataSet.StaffRow dr in staffRows)
    {
    if(dr.StaffID==_staffID)
    rowID=i;
    i++;
    }

    //update the staff datarow with the new values:
    _dsUserData.Staff[rowID].Firstname=<some value>;

    etc. then I do the same for the child table (Role) rows:

    //find the index of the child Role row to update (where
    StaffID=_staffID)
    i=0;
    int roleRowID=0;
    foreach(UserDataSet.RolesRow rr in
    _dsUserData.Staff[rowID].GetRolesRows())
    {
    if(rr.StaffID==_staffID)
    roleRowID=i;
    i++;
    }

    //update the Role datarow with the new values:
    _dsUserData.Roles[roleRowID].GroupID=<some value>

    etc ...
    Doug, Dec 2, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    3
    Views:
    585
  2. TB
    Replies:
    8
    Views:
    73,142
    allAboutMe
    Jun 28, 2012
  3. debiken
    Replies:
    0
    Views:
    262
    debiken
    Nov 17, 2003
  4. debiken
    Replies:
    1
    Views:
    361
    Mike Moore [MSFT]
    Nov 18, 2003
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    279
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page