Results 1 to 3 of 3

Thread: [resolved] updating an xml dataset - not working?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    280

    [resolved] updating an xml dataset - not working?

    hi,

    I have an app i wrote, it involves a list of data that is sourced from an xml structure - its horrible for the user to use as the list keeps reordering while they use it - this is down to the way i have coded it!!

    I have problems updating a .net dataset - I cannot updata fields within and have to delete the whole line and re-add it with a new one - seems hardwork just to update a field value!

    eg

    VB Code:
    1. DataRow obj_newrow  = cur_dataset.Tables["configset"].NewRow();
    2. obj_newrow[0]  = cur_dataset.Tables["configset"].Rows[int_tab_count].ItemArray[0].ToString();
    3.  
    4. cur_dataset.Tables["configset"].Rows.InsertAt(obj_newrow,int_tab_count);
    5. cur_dataset.Tables["configset"].Rows.RemoveAt((int_tab_count+1));

    I cannot see why this is - I cannot make the following demo code work - the "after" message returns "fieldvalue1"




    VB Code:
    1. test.xml =
    2.  
    3. <?xml version="1.0" standalone="yes"?>
    4. <testxml>
    5.   <configset>
    6.     <field1>fieldvalue1</field1>
    7.     <field2>fieldvalue2</field2>
    8.     <field3>fieldvalue2</field3>
    9.   </configset>
    10. </testxml>
    11.  
    12.  
    13. ---
    14.  
    15. System.Data.DataSet cur_dataset = new DataSet();
    16. cur_dataset.ReadXml("C:\\test.xml");
    17.  
    18. MessageBox.Show("before=" + cur_dataset.Tables["configset"].Rows[0].ItemArray[0].ToString());
    19.  
    20. cur_dataset.Tables["configset"].Rows[0].ItemArray[0] = "newvalue";
    21.  
    22. MessageBox.Show("after=" + cur_dataset.Tables["configset"].Rows[0].ItemArray[0].ToString());

    I have also tried adding:-

    VB Code:
    1. cur_dataset.Tables["configset"].Rows[0].AcceptChanges();
    2. cur_dataset.Tables["configset"].AcceptChanges();
    3. cur_dataset.AcceptChanges();

    I cannot get set row0, field0 to "newvalue" other than copying the whole record into a new datarow and doing the insertatr/removeat

    is this correct or am i doing something wrong,

    many thanks for any comments,
    cheers AJP

    ps - ms's site seems to say this is do-able - see http://msdn.microsoft.com/library/de...sindataset.asp
    Last edited by jpritchard; Dec 13th, 2005 at 04:33 AM. Reason: [resolved]
    Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor

    Real programmers use less....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: updating an xml dataset - not working?

    The ItemArray property is supposed to be used to get and set ALL the values in a row in one go. The way you are doing it, you get the array of field values and change one of the values in the array, but then you don't pass the updated array back to the ItemArray property. If you wanted to use the ItemArray property you would have to do it like this:
    Code:
    object[] myArray = cur_dataset.Tables["configset"].Rows[0].ItemArray;
    
    myArray[0] = "newvalue";
    cur_dataset.Tables["configset"].Rows[0].ItemArray = myArray;
    There is no point to using the ItemArray property in this situation though. Just set the field value directly:
    Code:
    cur_dataset.Tables["configset"].Rows[0][0] = "newvalue";
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    280

    Re: updating an xml dataset - not working?

    hi,

    thankyou - I thought i was doing something stupid!.

    I can now remove a load of removeat/insertat statements within my program.
    I had spent most of yesterday morning wondering what i was actually doing wrong before I asked here!.

    much appreciated for your help again - thankyou,

    cheers AJP
    Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor

    Real programmers use less....

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