Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello!

I have a huge problem with the data exchange of a server database and a mobile database( sdf ).
At first I load the data with a normal select from the server to my DataSet and then
i set the table rows to added and use the DataTableAdapter.Update() command to fill the mobile database.

The problem appears if I do it a second time because I got an exception with a primary key violation. Before i fill my mobile db I delete the whole table with the
delete-command.

Why do i get such an exception if no data is in my mobile database??

Kind regards,
thomas
Posted
Comments
CodingLover 11-Apr-11 7:39am    
Did you filtered only the non-read data from the server database ?

Seeing the code would help, but did you:
- accept the changes in the datatable after inserting
- clear all the rows from the data table before re-inserting (I mean you don't have duplicates in the datatable)
 
Share this answer
 
The "table" variable is my full loaded DataTable from the ServerDB.

So I try to delete the whole table in my mobile Ce DB and then to insert the data in this one.

The first time it works, the second time it fails because of the above mentioned primary key violation.

I think the DataTableAdapter should accept the changes after the insert and the table is cleared before refill the data.

_adpList[table.TableName].InsertCommand.Connection.Open();
     new SqlCeCommand("Delete From " + table.TableName, (SqlCeConnection)_adpList[table.TableName].SelectCommand.Connection).ExecuteNonQuery();
     _adpList[table.TableName].InsertCommand.Connection.Close();

      for (int i = 0; i < table.Rows.Count; i++)
      {
          table.Rows[i].SetAdded();
      }


      int rows = _adpList[table.TableName].Update(table);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900