DataAdapter Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phill

    #1

    DataAdapter Problem

    I have an PPC app that calls a web service which returns
    a dataset. I am trying to load this dataset into a SQL
    CE table called "Route_Shee ts". It goes through the
    motions, but no data is inserted. I have added code to
    create an XML file to verify that data is returned from
    the web service is good, it is. Here is my code. Please
    help.

    DataSet dsRemote = new DataSet();
    dsRemote = ws.GetRouteShee t(2);

    SqlCeConnection conn = new SqlCeConnection ("Data
    Source=" + LocalStorage.Fi leName);
    SqlCeDataAdapte r da = new SqlCeDataAdapte r();
    da.SelectComman d = new SqlCeCommand("S ELECT * FROM
    ROUTE_SHEETS", conn);
    SqlCeCommandBui lder cb = new SqlCeCommandBui lder(da);

    conn.Open();

    da.Fill(dsRemot e,"Route_Sheets ");

    int rowsaffected = da.Update(dsRem ote,"Route_Shee ts");

    conn.Close();

  • B Mermuys

    #2
    Re: DataAdapter Problem

    Hi,
    [inline]

    "Phill" <anonymous@disc ussions.microso ft.com> wrote in message
    news:0ee001c3a2 14$e65e4810$a10 1280a@phx.gbl.. .[color=blue]
    > I have an PPC app that calls a web service which returns
    > a dataset. I am trying to load this dataset into a SQL
    > CE table called "Route_Shee ts". It goes through the
    > motions, but no data is inserted. I have added code to
    > create an XML file to verify that data is returned from
    > the web service is good, it is. Here is my code. Please
    > help.
    >
    > DataSet dsRemote = new DataSet();
    > dsRemote = ws.GetRouteShee t(2);
    >
    > SqlCeConnection conn = new SqlCeConnection ("Data
    > Source=" + LocalStorage.Fi leName);
    > SqlCeDataAdapte r da = new SqlCeDataAdapte r();
    > da.SelectComman d = new SqlCeCommand("S ELECT * FROM
    > ROUTE_SHEETS", conn);
    > SqlCeCommandBui lder cb = new SqlCeCommandBui lder(da);
    >
    > conn.Open();
    >
    > da.Fill(dsRemot e,"Route_Sheets ");
    >
    > int rowsaffected = da.Update(dsRem ote,"Route_Shee ts");
    >
    > conn.Close();
    >[/color]

    The problem is that the dataset you get from the webservice probely
    contains a table Route_Sheets where all DataRow's states are set to
    'Unchanged'. In this case, your update on da, doesn't work, the rows aren't
    marked as 'Added'...

    The solution isn't easy, because you cannot change the row state yourself.

    Some (not so fun) solutions:

    * The webservice that returns the dataset can be modified, so that the rows
    stay marked as 'Added', this can be done, by setting AcceptChangesDu ringFill
    property to false before calling Fill on a DataAdapter

    * Add a copy of each row and delete the original

    DataTable dtRoutes = dsRemote["Route_Shee ts"];
    for (int i=0; i< dtRoutes.Rows.C ount; ++i)
    {
    dtRoutes.Rows.A dd ( dtRoutes.Rows[0].ItemArray ); // 0!
    dtRoutes.Rows.R emoveAt(0); // 0!
    }
    da.Update ( dtRoutes );

    * Manually updating row by row via the InsertCommand property of the
    CommandBuilder


    HTH
    greetings


    Comment

    Working...