CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Posts
    21

    Exclamation Changing data in DataSet

    Hi friends,

    I have one question about changing data in the DataSet. Whether changing data in DataSet in the manner described below is correct? Here is the code:

    OleDbConnection* dbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=myData.mdb");

    OleDbDataAdapter* da = new OleDbDataAdapter("SELECT * FROM Customer", dbConn);

    DataSet* ds = new DataSet("myDataSet");

    // Fill the DataSet
    da->Fill(ds);

    // Is this changing (updating) data in DataSet is correct ???????????
    ds->Tables->Item[0]->Rows->Item[0]->Item[1] = S"Jure";
    ds->Tables->Item[0]->Rows->Item[0]->Item[2] = S"Smith";
    // etc.

    OleDbCommandBuilder* cb = new OleDbCommandBuilder(da);

    DataSet* dsChanges = ds->GetChanges();

    if (dsChanges != NULL)
    {
    da->Update(dsChanges);

    ds->AcceptChanges();
    }

    This code works correct, but I’m not sure that this operation is regular:
    ds->Tables->Item[0]->Rows->Item[0]->Item[1] = S"Jure";

    Please, help me.
    Thanks!

  2. #2
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    Re: Changing data in DataSet

    Its ok
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  3. #3
    Join Date
    Dec 2004
    Posts
    21

    Re: Changing data in DataSet

    Thanks a lot!!!

  4. #4
    Join Date
    Apr 2005
    Posts
    5

    Re: Changing data in DataSet

    Hi,

    You can do like this also.

    You can create a DataRow object.

    drwuser=myDataSet.Tables("AccountsTable").NewRow
    drwuser("code")=code.text
    drwuser("name")=name.text

    myDataset.Tables("AccountsTable").Rows.Add(drwuser)


    <snip>
    Last edited by Brad Jones; May 3rd, 2005 at 08:26 AM. Reason: Removed SPAM / Advertising portion of post.

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