VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Strange Issue With VB .NET Datagrid Posted by YoShIe66 on 6 Jan 2006 at 1:43 PM
I'm working on an application that uses a dataset containing four datatables and a single datagrid I use to display each of them as I need to see their contents. When the datagrid is displayed, I bind it's datasource attribute to the required datatable. On loading each of the tables, this works very well.

The problem I am seeing is that if I bring up table(0) or table(1) and then make changes to the datagrid directly, those changes are not carrying down to the connecting datatable. Also, if I make a change directly to table(0) or table(1) and then refresh the datagrid, I also do not see the changes.

What makes this even stranger is that if I then load either table(2) or table(3) (which are identical in design), they function as I would expect: changes to the dagarid carry directly to the connecting datatable and changes to the datatable are visible upon using refresh().

It almost appears as though the databinding between tables(0) and table(1) is getting broken immediately after the table is loaded into the datagrid (I can see the data in the grid upon loading, so I know for sure it gets atleast that far).

Anyone have an idea what could be causing this?
Report
Re: Strange Issue With VB .NET Datagrid Posted by YoShIe66 on 11 Jan 2006 at 8:17 AM
After several hours of line-by-line tracing, I have managed to figure out what the problem was. It appears to be an error in the documentation on datasets. This is the problem:

In the documentation (and I have checked it in several books and in Microsoft's help), in order to duplicate a dataset (and the contained tables), you are to use something like this:

Private Sub CopyDataSet(ByVal myDataSet As DataSet )
   ' Create an object variable for the copy.
   Dim copyDataSet As DataSet
   copyDataSet = myDataSet.Copy() <====
   ' Insert code to work with the copy.
End Sub


And of course, you are to use "clone()" to duplicate the structure but not the data, as below:

Private Sub GetClone(ByVal myDataSet As DataSet)
   ' Get a clone of the original DataSet.
   Dim cloneSet As DataSet
   cloneSet = myDataSet.Clone()
   ' Insert code to work with clone of the DataSet.
End Sub


Well, it turns out that for some reason, in Visual Studio 2003, the copy() is not correct. I was using it to duplicate a dataset into an object (which does all these calculations, etc) and then copying it back out to the parent form (from which it originally came). At the point where I used copy(), the dataset was not being properly copied. Instead, it acts more like clone() in that I get an empty dataset. The syntax that actually works for me looks more like this:

Private Sub CopyDataSet(ByVal myDataSet As DataSet )
   ' Create an object variable for the copy.
   Dim copyDataSet As DataSet
   copyDataSet = myDataSet
   ' Insert code to work with the copy.
End Sub


This copies both the dataset completely, as well as all of the tables within it (and their data), thus resolving the problem I was seeing. Basically, I was saving the tables properly (and doing the calcs), but then when the dataset was returned to the form, it was not properly being copied (thus the entries in my datagrid were being overwritten by duplicate "old" data)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.