none
One DataAdapter per Table for Updates? RRS feed

  • Question

  • Hello, I am in the process of learning ADO.NET for a new project, so - n00b question here.

    I am creating multiple tables in my DataSet, from multiple SQL Server tables. Some (but not all) of these will have Update called on them with new and/or changed rows. Can I reuse the same SqlDataAdapter to Fill the DataSet tables (by creating a new SelectCommand for each Fill), and then also create a new SqlCommandBuilder for the current table referenced in the SelectCommand, to be able to call Update (for each table as appropriate) at the end of the data manipulation? Or must I create a new SqlDataAdapter for each table? Another way to ask, I think: do the Select/Delete/Insert/UpdateCommand commands really live in the SqlDataAdapter or do they actually somehow get assigned to the (current) Table in the DataSet? It seems like the answer is the former, but I wanted to confirm. Thanks for the clarification.

    Sunday, April 22, 2012 11:55 PM

Answers

  • Why would you want to do that. I know that from a strange twist in my mind I wanted this also to do once, but in fact there is not any reason for that. 

    The dataAdapter contains a bunch of information depended to one table. Using one dataadatpter has the following results.

    1. Your program becomes more difficult to maintain
    2. The processing will be slower
    3. The change on errors is higher

    But maybe you have another reason why you want to use one dataadapter instead of more related to the database tables?


    Success
    Cor

    Monday, April 23, 2012 7:38 AM

All replies

  • Why would you want to do that. I know that from a strange twist in my mind I wanted this also to do once, but in fact there is not any reason for that. 

    The dataAdapter contains a bunch of information depended to one table. Using one dataadatpter has the following results.

    1. Your program becomes more difficult to maintain
    2. The processing will be slower
    3. The change on errors is higher

    But maybe you have another reason why you want to use one dataadapter instead of more related to the database tables?


    Success
    Cor

    Monday, April 23, 2012 7:38 AM
  • My thinking is, if I don't have to use more than one DA, why do so? Of course if I can't reuse one, then I will use as many as necessary.

    Monday, April 23, 2012 12:54 PM
  • I wrote that I once also had once that same mind twist like you tell now.

    Be aware reusing is not constantly creating everything new except the reference.

    A data adataadapter is just a reference to an inbuild Class.

    If you do it in the way you think is cheaper, you have constantly to change all the settings of that single dataadapter.

    If you use more dataadapters you only use a name, which references to all those already set settings. 

    The first if will take twice as must memory, and many more processing, and be harder to maintain.

    Keep in mind they are not stupid at Microsoft, especially not the AdoNet team, if it had been better like you wrote, they had created it like that.


    Success
    Cor


    Monday, April 23, 2012 3:18 PM