Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / November 2005

Tip: Looking for answers? Try searching our database.

Problem updating from Dataset using DataAdapter to SQL server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cyr1dian - 19 Nov 2005 12:51 GMT
Hi all,

Situation:
----------
1) I've created DataAdapters to about a dozen tables in msAccess (1  
adapter per table)
2) I've created a dataset using the visual XML designer in VS2003, adding  
all the realtions=> results in dataset class "dsPS"
3) Retepeated step one for an identical (as far as possible) datastructure  
in MS SQLserver 2000
4) Created two instances of the Dataset class, namely "PSc" and "PSo"
5) Loaded the msAccess data into PSc using the fill command about a dozen  
times.
6) Did the same thing with the data from SQLserver, put that into PSo  
using msSQL dedicated DataAdaptors

Scenario
--------
So far so good, no problems. There's actually a third database that I use  
to register some metadata but it's not directly tied into either of these  
and works fine (that one is in the same SQLserver btw).

The basic idea is to sync the two databases where msAccess is leading with  
some users on the msAccess db and some on the SQLserver. The SQLserver  
"copy" starts off empty, msAccess is the leading database. The  
synchronisation goes perfectly internally (in the datasets), all the  
feedback is as expected. However once the datasets are sorted out, data  
must then be inserted into the SQLserver. Seems pretty straightforward and  
something like: myDataAdapted_formyMyTable.Update(dsPSo.myTable); But it  
doesn't insert any rows.

Situation at time of problem
----------------------------
a) The dataset "PSo" has a correct rowcount
b) SQLserver works because I can insert into other tables (the metadata db)
c) All tables are empty
d) The updates are called in a sequence that takes the relations into  
account (parents before children)
e) Nothing happens when the code runs, it just traces over the code  
without results in SQLserver

Bottomline
----------
I should be able to use one DataSet class for two sets of DataAdapters if  
the structure is identical right? What am I missing?

Thnx for any help!
Bart Mermuys - 19 Nov 2005 15:38 GMT
Hi,

>Hi all,
>
[quoted text clipped - 26 lines]
>something like: myDataAdapted_formyMyTable.Update(dsPSo.myTable); But it
>doesn't insert any rows.

>Situation at time of problem
>----------------------------
[quoted text clipped - 12 lines]
>
>Thnx for any help!

If it understand it correcty then you're doing something like Access ->
PSc -> PSo -> SqlServer ?

The reason rows are not inserted with a DataAdapter.Update is because the
rows don't have an "Added" rowstate, they are not marked as "Added" so the
DataAdapter doesn't insert them.

A DataAdapter.Fill will add rows to the DataTable, *but* by default
AcceptChanges is called, marking these rows as "Unmodified".  You can change
this behaviour by setting DataAdapter.AcceptChangesDuringFill. (note that
AcceptChanges is also called after an Update).

If you copy DataRow's from one DataTable to another and you use ImportRow
then the RowState is the same as the original.

If you copy DataRow's using LoadDataRow, you can choose whether the rows
should be Accepted or not, if they're not accepted they will have an "Added"
or "Modified" state otherwise they will have an "Unmodified" state. eg.  (
table2.LoadDataRow( table1.Rows[0].ItemArray, false ); )

If you add rows using AddNew/Rows.Add then by default they will have an
"Added" state.

Calling AcceptChanges always sets the rowstate to "Unmodified".

HTH,
Greetings
Cyr1dian - 19 Nov 2005 17:09 GMT
Bart you da man, ty!

simply setting that property to false already did the trick (resulting in  
various conversion errors but I was very happy to see them ;) )

I'll have to look deeper into these rowstates since they are obviously  
more important than I gave them credit for.

I had been working on this for over a day so again: thnx!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.