Results 1 to 5 of 5

Thread: [RESOLVED] Add additional Rows to Dataset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Resolved [RESOLVED] Add additional Rows to Dataset

    I have a parent/child relation I am trying to create fow 2 datasets.
    The parent ds consusts of a range of PO Header information

    After I fill this dataset I loop through it getting the PO number. I then take that value and execute another sql statement on the DETAIL file and fill a dataset(dtlDS) for EACH row in the parent. How do I add to this dtlDS for each row? I am getting no CHILD data in the merge. Should I be filling to a datatable and do an add.row and THEN dump into the dtlDS??

    Thanks

    gollnick
    William E Gollnick

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

    Re: Add additional Rows to Dataset

    You don't use two DataSets. That's the whole point of a DataSet: to contain DataTables and the DataRelations between them. Use one DataSet with two DataTables and one DataRelation. Populate the parent table first and then the child table.
    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
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Re: Add additional Rows to Dataset

    OK... I tried it that way..... see below... Got this error on the first pass

    Object reference not set to an instance of an object.

    YesNo = 0
    Try
    Adapter.Fill( DS1 , "MyTable")
    Catch Error Type( System.Exception )
    Throw Error
    YesNo = 1
    EndTry
    ForEach CountRow Collection( ds1.Tables(0).Rows)
    MyNewKey = CountRow(KeyPart2parmfield).ToString()
    *This.CloseConnection()
    SetSqlCommand_Single_File_1_Parm (JointoFile , KeyPart3parmvalue , MyNewKey )
    *This.OpenConnection()
    Try
    Adapter.Fill( Result )
    Catch Error Type( System.Exception )
    Throw Error
    EndTry
    ForEach CountRowDtl Collection( Result.Tables(0).Rows)
    dr = ds1.Tables("MyDetail").NewRow() error thrown here

    dr = countrowdtl
    ds1.Tables("MyDetail").Rows.Add(dr)
    EndFor
    EndFor

    I want this second table within dataset ds1 (the MyDetail one) to contain corresponding po data for the ds1(MyTable) only

    thanks

    gollnick
    William E Gollnick

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Add additional Rows to Dataset

    So put it in there... you're still creating two datasets needlessly... just fill both tables in the same dataset...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Re: Add additional Rows to Dataset

    Oh ... wait a second... In my relations section I was nameing the wrong sub table.. My bad... You are correect.. one dataset.. multiple tables and no fat fingers.
    List this closed. Thank you
    gollnick
    William E Gollnick

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