locked
Updating one Dataset from another Dataset RRS feed

  • Question

  • Hi,
    I have created a DataSet(dsLocal) containing rows from local database that I wish to update with the rows taken from another dataset (dsWeb).

    dsWeb dataset may contain Newly added rows and/or modified rows.

    dsweb is populated from the Web server Database and dsLocal is populated from Local database

    Both Local and Web server database schema are same.

    What dataset methods/properties should i use?

     

    • Moved by Max Wang_1983 Friday, April 22, 2011 9:41 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Friday, October 19, 2007 9:30 AM

Answers

  •  

    Thanks Sreevi,

     

    But Source database is SQL Standard and Destination database is SQL Express not SQL CE.

     

    Wednesday, November 21, 2007 6:14 AM

All replies

  • Here is the sample code, that i am updating destination database with source database which are having same schema.

     

     

    foreach (string sql in TablesList)
                    {
                        DataTable sourceTable = new DataTable();
                        DataTable destTable = new DataTable();
                        SqlCeDataAdapter daAdapter = new SqlCeDataAdapter(sql, sourceConn);
                        SqlCeDataAdapter destAdapter = new SqlCeDataAdapter(sql, destConn);
                        daAdapter.Fill(sourceTable);
                        destAdapter.Fill(destTable);

                        for (int i = 0; i < sourceTable.Rows.Count; i++)
                        {
                            drCurrent = destTable.NewRow();
                            for (int j = 0; j < sourceTable.Columns.Count - 2; j++)
                            {
                                drCurrent[sourceTable.Columns[j].Caption] = sourceTable.RowsIdea[j];
                            }
                            destTable.Rows.Add(drCurrent);
                        }

                        // BEGIN SEND CHANGES TO SQLCE
                        SqlCeCommandBuilder objCommandBuilder = new SqlCeCommandBuilder(destAdapter);
                        destAdapter.Update(destTable);
                    }

    Monday, November 19, 2007 4:36 PM
  •  

    Thanks Sreevi,

     

    But Source database is SQL Standard and Destination database is SQL Express not SQL CE.

     

    Wednesday, November 21, 2007 6:14 AM
  •  

    i am using yout code in my application but its giving me error as my identity column is GUID and error is Type of value has a mismatch with column typeCouldn't store <System.Data.DataRow> in DoorId Column.  Expected type is Guid.

    on following line can u give me whole sample code

    drCurrent[sourceTable.Columns[j].Caption] = sourceTable.Rows[j];

     

    please reply Soon its urgent

     

     

    Friday, February 1, 2008 8:13 AM