|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dataset HasChanges function not true when Dataset is passed as variablehave 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 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 <darjon***@gmail.com> schreef in bericht Show quoteHide quote news:1151346727.428542.66710@m73g2000cwd.googlegroups.com... >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 > 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 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. -- Show quoteHide quoteTerry "darjon***@gmail.com" wrote: > 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 > > 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. -- Show quoteHide quoteTerry "darjon***@gmail.com" wrote: > 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 > > 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] Show quoteHide quote "Terry" wrote: > 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. > -- > Terry > > > "darjon***@gmail.com" wrote: > > > 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 > > > > Ok, forget the statement about AcceptChanges ... My Bad!
-- Show quoteHide quoteTerry "darjon***@gmail.com" wrote: > 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 > > Darian,
Why have you commented out that If haschanges text in your code, are you sure you are talking about the same? Cor <darjon***@gmail.com> schreef in bericht Show quoteHide quote news:1151349501.370760.134280@u72g2000cwu.googlegroups.com... > 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 >
ASP.NET web application - date conversions UK date format?
Building a single EXE file in VB 2005? default in .NET byref or byval? Build Failed - 0 Errors button flash with red and white color DataGridView row background color Adding ActiveX controls at runtime and threading How to gain access to objet in different class ? Define a compilation switch Listbox help |
|||||||||||||||||||||||