dataset.update to SQL server CE

G

Guest

hi

Im trying to insert a table from a distant SQLSERVER to a local SQLSERVER CE

//First, I retrieve the table from the distant DB, this operation is done correctly I have tested it already

DataSet ds = new DataSet()
SqlDataAdapter adapter = new SqlDataAdapter(SqlServerCmd);
adapter.Fill(ds)

//then I want to update the local DB with the dataset

SqlCeDataAdapter adapterce = new SqlCeDataAdapter(SqlceCMD)
adapterce.Update(ds,"Table")

//..

The application dont make any exception or error , but the Table is empty, in fact I think I need to define a mapping or something but I dont know how to tell the dataset to map a table on my local SQL server CE
 
W

William Ryan eMVP

Have you confirmed that the dataset HasChanges? If not, update isn't going
to do much of anything. Here are a few guidelines in debugging this
problem, http://www.knowdotnet.com/articles/efficient_pt4.html If none of
them fix it, let me know and we'll take it from there.

Bill
dys said:
hi,

Im trying to insert a table from a distant SQLSERVER to a local SQLSERVER CE.

//First, I retrieve the table from the distant DB, this operation is done
correctly I have tested it already:
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(SqlServerCmd);
adapter.Fill(ds);


//then I want to update the local DB with the dataset:

SqlCeDataAdapter adapterce = new SqlCeDataAdapter(SqlceCMD);
adapterce.Update(ds,"Table");

//...


The application dont make any exception or error , but the Table is empty,
in fact I think I need to define a mapping or something but I dont know how
to tell the dataset to map a table on my local SQL server CE.
 
W

William Ryan eMVP

If I understand you correctly, you are just filling the dataset to call
update so the data transfers to another table? If that's the case, then
everything referenced in the first article applies in that the Update is
totally dependent on Rowstate. The adapter will loop through the rows,
check their rowstate, and apply the respective command if it's in fact
added/modified/deleted.

Remember that HasChanges dictates whether or not anything is going to
happen, notice in the article that you can call update 1000 times and if
HasChanges is false, the StateChanged event handler will not fire proving
that nothign is happening.

So, the solution:

Very simple. When you call the .Fill method of the first dataadapter, set
the .AcceptChangesDuringFill property to false. This will give you a
rowstate of added for all the rows, use the exact same dataset/datatable and
just call update with the second dataadapter

DataAdapter1.AcceptChangesDuringFill = false;
DataAdapter1.Fill(myDataSet, "MyTable");
DataAdapter2.Update(myDataSet, "MyTable");
//the dataset and table name should match exactly the fill statement.
There's a walk through here
http://www.knowdotnet.com/articles/datasetmerge.html
but that's all there is to it.

Let me know if you have any problems.

Bill
 
W

William Ryan eMVP

My pleasure. I think you should be good to go with just the
acceptchangesduringfill, but if you have a problem let me know and we'll get
you through it

Cheers,

Bill
 
G

Guest

Ok I have a little pb here

When I set the adapter1.AcceptChangesDuringFill to false, I have an InvalidOperationException (.Message: Insert) caught when calling the adapter2.updat

btw, I cant read your article because my internet is restricted to professionnal websites.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top