Need help fast, DataSet question!

  • Thread starter Thread starter Lars Netzel
  • Start date Start date
L

Lars Netzel

I'm trying to copy data from two tables in a Source db into two Tables in a
Destination db and the Tables designa are the same.

I created 4 adapters...

2 for the two tables in the source db
2 for the 2 tables in the destination db

Then I filled a SourceDataSet with the Source adapters

and then I update the destination adapters with the SourceDataset.

But the information is not copied, what can I do???

I need help really fast, please!

/Lars
 
Hi Lars,

First of all, we try to learn as well from this newsgroup and like to have
some feedback on questions.

I don't know how it is with others, however when I give an answer I get the
idea, that you never read it.

To give an answer on your question. What do you mean with copy because I get
the idea because you are talking about a dataadapter, that it is not this
code?

dim datasetNew as new dataset = datasetOld.copy

Cor
 
Okay I have this code!

Private Sub Importdata()

Try

dsDestination = dsSource.Copy

adpDestinationDisk.Update(dsDestination, "Disktable")

adpDestinationEvent.Update(dsDestination, "Eventtable")

Catch ex As Exception

MsgBox(ex.Message)

End Try

DataGrid2.DataSource = dsDestination

End Sub


I dataset is updated alright but the changes are never written into the
Database associated with the Destination adapters.

I don't get any error, the Update Just does'nt seem to happen. But the
Datagrid shows the dataset fine.

And about the first thign you wrote, you mean I never say thank you or you
mean I don't answer questions?

I do both, but as you probably have noticed, i'm not that good yet and most
questions I have no idea abotu how to answer.

I'm very thankful I get answers in here, it's helping me a lot!

/Lars
 
Hi Lars,

Am I right that the second update does not work and the first does.

The dataadapter has an automaticly accept.changes in it with a full dataset.
So all rowstates will be set as done and your second update *should* never
work.

If this does not answer your question, reply?

Cor
 
You might be on to something here.. I never thought about that the second
update might never happen and that will explain why the database in not
updated I guess.. but what can I do About this?

Why "should" it not work?
/Lars
 
Hi Lars.

I think you can try to use a copy dataset to update, or you can do the
first update using dataset.getchanges because I saw than the datarowsetting
is not changed. However I am not sure if that last is as it should be or
that it is a bug and when it is the last you can get problems in future, I
am not using that one anymore.

Have a look at this article for the working of the update, in my opinion it
describes that very well.

http://msdn.microsoft.com/library/d...stemdatacommondataadapterclassupdatetopic.asp

(Did you look at the command haschanges too, it is very usefull)
if dataset.haschanges then
update
end if

If not clear, reply?

Cor
 
Still don't get it.

I mean... My Datasets are all updated Fine... but Not the adapters, but the
don't give me any error!

/Lars
 
I have gone the booring way now... I fiuxed it wil ExecuteNOnQuerys and
wrote the Updates myself.. I have fixed my "mission" but not in the way I
wanted and I still dont' get why I can't

Fill one Dataset with one adapter... copy it and then use the DatasetCopy to
update the another adapter.

/Lars
 
When I use the HasChanges check it seems the dataset is actually not
updated.. It never goes into my IF statement although dsDestination is
originally Empty and the dsSource.Copy is not giving an error...

Private Function Importdata() As Boolean
Try
dsDestination = dsSource.Copy
If dsDestination.HasChanges Then
adpDestinationDisk.Update(dsDestination, "Disktable")
adpDestinationEvent.Update(dsDestination, "Eventtable")
DestinationGrid.DataSource =
dsDestination.Tables("Eventtable")
Return True
Else
DestinationGrid.DataSource() =
dsDestination.Tables("Eventtable")
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try

/Lars
 
Hi Lars,

What is the code before that, where you put the changes in the dataset.
The most made mistake is that people put an dataset.acceptchanges somewhere
before the update, what means that all updates will be set as done.

Cor
 
The only code I have is in The Form_Load

adpSourceDisk.Fill(dsSource, "DiskTable")
adpSourceEvent.Fill(dsSource, "EventTable")
SourceGrid.DataSource = dsSource
adpDestinationDisk.Fill(dsDestination, "DiskTable")
adpDestinationEvent.Fill(dsDestination, "EventTable")
DestinationGrid.DataSource = dsDestination

'***************************************************************

This gives me an empty Grid, and that's fine, it should be empty in the
beginning.

'And then the rest that you've seen before

'***********************************************************

Private Function Importdata() As Boolean
Try
dsDestination = dsSource.Copy
If dsDestination.HasChanges Then
adpDestinationDisk.Update(dsDestination, "Disktable")
adpDestinationEvent.Update(dsDestination, "Eventtable")
DestinationGrid.DataSource =
dsDestination.Tables("Eventtable")
Return True
Else
DestinationGrid.DataSource() =
dsDestination.Tables("Eventtable")
End If
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
Enf Function

/lars
 
Lars,
David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS press
discusses how to get the DataSet to copy from one DB to another.

Unfortunately my copy of Sceppa's book is at the office.

Sceppa's book is both a good tutorial on ADO.NET as well as a good desk
reference once you know ADO.NET

Hope this helps
Jay
 
YOU ROCK!

That was all I had to do.. set the property to False!

Thank you very much!

Best Regards!
/Lars
"Cor Ligthert" <[email protected]> skrev i meddelandet Hi Lars,

I think that I now understand, what you mean with copying.

When you fill all datarowstatuses are unchanged, that is done by the fill which does to an automatic acceptchanges.

You can set it as changed by dataadapter.acceptchangesduringfill property to false

http://msdn.microsoft.com/library/d...aadapterclassacceptchangesduringfilltopic.asp

I think you are almost there now?

Cor
 
Back
Top