none
Return back a whole refreshed data to a large database RRS feed

  • Question

  • **Edit :**

    -*Changed the question into a different simpler form*-

    Please review this piece of code :
    I am given an error,

    **Error :**

    *Update unable to find TableMapping['Table'] or DataTable 'Table'.*

    The DataSet Strongly typed,
    All the Data is gathered  in a Generic List "ListProducts" for offline processing,
    reordering and making it ready to be the new version of the database.

    one column's name in the database differs from the list's field :
    "Title" should mapped with the column : "TitleInDb"


        SqlCeDataAdapter Adapter;
        DsProducts Ds1Products ; // Strongly Typed
        DataTable dtNew = new DataTable("Products");
        DataColumn dc;
        DataRow[] updRows;
        // Fields : Name , Title, Price
        
        dc = new DataColumn("Name", typeof(string));
        dtNew.Columns.Add(dc);
        dc = new DataColumn("TitleInDb", typeof(string)); // The difference is by a reason
        dtNew.Columns.Add(dc);
        dc = new DataColumn("Price", typeof(string));
        dtNew.Columns.Add(dc);
        dtNew = updRows.CopyToDataTable();
        Ds1Products.Tables.Add(dtNew);
        
        foreach (var col in dtNew.Columns)
        {
            Console.WriteLine(col.ToString());
            Console.WriteLine(col.GetType());
        }
        
        Adapter.Update(Ds1Products);
    ---
    Running this, Iterating through the new columns I see that there is no change to the "Products" table which I thought should have been deleted at that time. Also the name of the new table `"dtNew"` seems to be `"table1"`

    **Additional Notes :**
    It uses Sql Compact 3.5

    *please review the code and give your ideas on this,
    I'm trying to make the whole database based on a refreshed Table (or DataRows[] )*
    • Edited by MHM-Mz Tuesday, July 3, 2012 4:44 AM
    Monday, July 2, 2012 6:52 AM

Answers

  • Hi Ms Bonnie,

    Yes you are right I didn't post anything related, sorry for the incompleteness,  and you guessed right I missed a piece which I forgot after a while not using this approach,

    Update Method of the DataAdapter needs Insertion Command on the new rows currently added,

    and this was the missed part,

    thanks anyone involved in the thread


    • Marked as answer by MHM-Mz Monday, July 9, 2012 5:19 AM
    • Edited by MHM-Mz Monday, July 9, 2012 5:29 AM
    Monday, July 9, 2012 5:19 AM

All replies

  • Why not trying it first in a working way before you start optimizing your code by adding generic lists and linq?



    Success
    Cor

    Monday, July 2, 2012 9:40 AM
  • Sorry friend didn't get you completely,

    If I get you right, I could tell that

    there were some traditional way doing this,

    All the code for this project is written in the best possible forms,

    and I want to learn about the question I've asked before combining it to the code,

    All the pieces of code were optimized, the whole project doing it's job about 10x faster than it's starting line. Also most of the pieces are reusable, so trying to understand each situation , alternatives, and trying the possible best solution.

    Also because the processes inside the project are really heavy, I need the Performance factor from the start.

    Now what I'm looking for is just to save the list "ListProducts" to the database.

    which way could you suggest, could you please help me on this ?

    my question is not regarding Parallelism

    ---

    Thoughts and Concerns

    If that's possible it could be good practice if I correct the table Mapping by Linq,

    or Don't know how could get help from DsProducts.ProductsDataTable to make it easier to map the columns,

    At last not sure on howto make the new table and save the database in a way specified above.

    Thanks in advance


    • Edited by MHM-Mz Monday, July 2, 2012 10:04 AM
    Monday, July 2, 2012 10:03 AM
  • My Thougths and Concerns.

    If you optimize do it then step by step and be sure you keep full control.

    I'm curious how it can run 10 times faster if it gives an error?

    Be also aware that Linq has nothing to do with performance, it is a way to write code in expressions and has a generator behind the scene which makes the same kind of code which could probably better be done by outstanding programmers. Generators makes seldom code which performs faster than the best programmer can do. (The generator is created by the same kind of programmers).



    Success
    Cor

    Monday, July 2, 2012 12:00 PM
  • thanks for the replies,

    but don't know why you are making questions of the question,

    I tried to clarify it more,

    You are wrong here, I didn't say ever Linq improved the performance 10 times !

    During the rebuild of the project achieved this,

    The question I asked is regarding some parts which I forgot or some pieces may be I have deal with them in some different ways, or missed something.

    Anyway any help you or any expert give will be appreciated

    -MHM-



    • Edited by MHM-Mz Tuesday, July 3, 2012 4:52 AM
    Tuesday, July 3, 2012 4:50 AM
  • I guess I don't understand why your Typed DataSet, DsProducts, doesn't already have the column called "TitleInDb"? And I don't see how creating a new DataTable from updRows.CopyToDataTable() is going to put any data into that column? The code you posted is obviously missing a few things, since you don't show anything about how the data ends up in updRows. What does your Adapter's update command look like? 

    Too many unanswered questions for me to make any kid of recommendations, because I really can't follow what's going on. Could you make it a bit clearer?


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Sunday, July 8, 2012 12:13 AM
  • Hi Ms Bonnie,

    Yes you are right I didn't post anything related, sorry for the incompleteness,  and you guessed right I missed a piece which I forgot after a while not using this approach,

    Update Method of the DataAdapter needs Insertion Command on the new rows currently added,

    and this was the missed part,

    thanks anyone involved in the thread


    • Marked as answer by MHM-Mz Monday, July 9, 2012 5:19 AM
    • Edited by MHM-Mz Monday, July 9, 2012 5:29 AM
    Monday, July 9, 2012 5:19 AM
  • Well, I'm glad you figured it out! =0)

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Monday, July 9, 2012 2:12 PM