Question about TableAdapter

Last post 09-13-2008 11:50 AM by ttcckky. 2 replies.

Sort Posts:

  • Question about TableAdapter

    09-12-2008, 10:21 AM
    • Member
      10 point Member
    • gater
    • Member since 03-19-2008, 2:05 PM
    • Posts 40

    What scenarios would I use the "Fill a DataTable" vs "Return a DataTable"?  What's the difference?   As far as I can tell they basically do the same thing...but there has to be a difference and I can't zero in on it. 

  • Re: Question about TableAdapter

    09-12-2008, 11:27 AM
    Answer
    • Contributor
      2,230 point Contributor
    • cameron_w
    • Member since 04-02-2008, 8:25 AM
    • South Africa
    • Posts 334

    It's sometimes quicker to return a DataTable:

    MyDataSet.MyDataTable MyNewTable = new MyDataSetTableAdapters.MyDataTableAdapter().GetData("param1","param2");

    But if the table you're trying to populate is inside a typed DataSet you can't assign the result to the dataset's table:

    //Doesn't work:

    MyDataSet MyNewDataSet = new MyDataSet();
    MyNewDataSet.My = new MyDataSetTableAdapters.MyDataTableAdapter().GetData("param1","param2");

    //Does work 

    MyDataSet MyNewDataSet = new MyDataSet();
    new MyDataSetTableAdapters.MyDataTableAdapter().Fill(MyNewDataSet.My, "param1","param2");

    There are no significant differences though 

    Please: Don't forget to click "Mark as Answer" on the post that helped you.

    Cameron Waldron
  • Re: Question about TableAdapter

    09-13-2008, 11:50 AM
    Answer
    • Member
      128 point Member
    • ttcckky
    • Member since 06-22-2008, 10:13 PM
    • Posts 29
    The different is using Fill, you don't need to handle connection open() and close().
Page 1 of 1 (3 items)