Dataset HasChanges function not true when Dataset is passed as variable

D

darjonase

I am having a problem, and I wonder if anyone could help me with it. I
have two methods. The first on a form calls the second method which is
located in a class lib.

'Form Method
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
'If imageDataSet.HasChanges Then
_databaseMethods.ProcessUpdates(imageDataSet)
'End If
End Sub

'Class Method
Public Sub ProcessUpdates(ByRef dsData As DataSet)
Try
If dsData.HasChanges(DataRowState.Modified) Then
Dim dsChangedDataSet As DataSet
dsChangedDataSet =
dsData.GetChanges(DataRowState.Modified)

If dsChangedDataSet.HasChanges Then
HandleDataSetErrors(dsChangedDataSet)
Else
UpdateImagesInDB(dsChangedDataSet)
End If
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub

When I pass the imageDataSet object to the ProcessUpdates method, the
..HasChanges function will always return a false. If, however, I check
the .HasChanges function on the imageDataSet object before it is
passed, it will return a true value.

Ideas on this one?
Darian Bonnell
 
C

Cor Ligthert [MVP]

Darjonase,

Can you try passing it ByValue.
Byval is a little bit more efficient in this procedure while it is the
normal way as this is done.

Cor
 
D

darjonase

That didn't seem to do anything. Also, this may help find an answer.
When I put the .HasChanges in the form method it is set to True as I
said before. When I then call the method in the class lib, the
..GetChanges method does not return anything at all.

Thanks for any help all,
Darian
 
G

Guest

I am not an expert on this subject, but haveing just read an article on this
subject .... Are you positive that changing it to 'ByVal' had no effect? You
need to be carefull when passing object references. ByVal does NOT create a
copy of the object, but a copy of the reference! ie a new pointer to the
DataSet object. Whereas, ByRef will pass a reference to the original
'reference'. So ByRef would allow you to change the original pointer to
'Nothing' for example. As best as I can understand it the ByRef argument is
an 'indirect' reference to the orgingal Object (DataSet in this example).
Again, I am not an expert and would like to hear from them on this subject.
 
G

Guest

Just looking at your code again... Don't you have to call 'AcceptChanges'
before you can call GetChanges? Also, in the calling routine, you are
looking at all changes and in the called routine you are filtering to only
changes of type 'Modified' so it is possible to true in the calling routine
and not true in the called routine.
 
G

Guest

Hi Terry

i believe you are right

dataset.getchanges()

Gets a copy of the DataSet that contains all changes made to it since it was
loaded or since AcceptChanges was last called.

or

dataset.getchanges(datarowstate)

Gets a copy of the DataSet containing all changes made to it since it was
last loaded, or since AcceptChanges was called, filtered by DataRowState.


regards

Michel Posseth [MCP]
 
C

Cor Ligthert [MVP]

Darian,

Why have you commented out that If haschanges text in your code, are you
sure you are talking about the same?

Cor
 

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