none
Datatable.addRow RRS feed

  • Question

  • What is the difference in :

         myDataTable.BeginInit();

         myDataTable.Rows.Add(row);

         myDataTable.AcceptChanges();

         myDataTable.EndInit();

    and:

         myDataTable.Rows.Add(row);

        

    and:

    string s = DtActivity.Rows[0].ItemArray[2].ToString();

    and

    string s = DtActivity.Rows[0][0].ToString();

        

     

     

     


    McC
    Friday, June 25, 2010 5:34 PM

Answers

  • You don't usually need the .BeginInit(), but you sometimes do need the .EndInit(), so you should always include at least that. And, if you're using the .AcceptChanges(), it should be after the .EndInit(). Be sure you understand the implications of using .AcceptChanges() ... once that statement is executed, the DataSet (or DataTable) will be considered to NOT have any changes (which is a problem if you need to update a database from it).

    And I prefer the second syntax in your second question ... infinitely more readable IMHO (and to make the two the same, you should have had this:

    string s = DtActivity.Rows[0][2].ToString();


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by John Basedow Monday, June 28, 2010 9:21 PM
    Saturday, June 26, 2010 6:16 PM

All replies

  • BeginInit is prevent usage of component before it is completely initilize. So if you want that no one use your component until it is full initilized, You can call the BeginInit in start of your operation and once initilization is completed you can call the EndInit.

    For the second question both have same thing but we are using different methods to access it, The first one is using array directly and second one is using the indexer.


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, June 25, 2010 5:55 PM
  • You don't usually need the .BeginInit(), but you sometimes do need the .EndInit(), so you should always include at least that. And, if you're using the .AcceptChanges(), it should be after the .EndInit(). Be sure you understand the implications of using .AcceptChanges() ... once that statement is executed, the DataSet (or DataTable) will be considered to NOT have any changes (which is a problem if you need to update a database from it).

    And I prefer the second syntax in your second question ... infinitely more readable IMHO (and to make the two the same, you should have had this:

    string s = DtActivity.Rows[0][2].ToString();


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by John Basedow Monday, June 28, 2010 9:21 PM
    Saturday, June 26, 2010 6:16 PM