Need sample code for using VB.NET code generated by MSDatasetGenerator

In a VB.NET project I've created an XSD file with a schema for a simple XML file that I wish to write to, and read from, a file (no SQL Server or other database involved).  Using the MSDatasetGenerator I created the VB.NET code that will serialize my XML to disk.  The code that gets generated is 500+ lines of code.  I'm looking for sample code or a document that describes how to use this generated code.

The following article:
http://blogs.msdn.com/bruce_jackson/archive/2004/08/20/217999.aspx
is a small sample application in C# that does the same kind of thing that I'm trying to do in VB.NET.  I would like a document that describes more of the class than this C# example and code that is in VB.NET instead of C#.

I appreciate any help.

Mike

mlazearAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
grayeConnect With a Mentor Commented:
OK... using the accounts table as an example, let's compare the "old way" with the new strongly-typed way:

<------------------- old way ------------------------->

' create a new row
Dim dr as DataRow = dt.NewRow()

' populate a few fields
dr("ID_Account") = 12
dr("Account") = "Some Name"

' add the row to the table
dt.rows.add(dr)

<------------------- new way ----------------------->

' create a "row" variable for the Account table
Dim dr As SOSOSDataset.AccountsRow = ds.Accounts.NewAccountsRow

' populate a few fields
dr.ID_Account = 12
dr.Account = "Some Name"

' add the row to the table
ds.Accounts.AddAccountsRow(dr)

The concepts and the steps required are identical.  The only benefit is that the fields are "strongly typed".    So, for example, if I wrote:

dr.ID_Account = "Hello" (and the ID_Account field was expecting an integer) the IDE would immediately flag that as an error.

However, using the "old way"

dr("ID_Account") = "Hello"   would compile without any errors, but would blow up at run time.

The "strongly typed" feature helps prevent silly programming errors like trying to enter a string into a database's integer field.

Perhaps you might wanna step back a minute and take a look at few articles/samples at:  http://home.hot.rr.com/graye/Articles/BeginningADO.htm and http://home.hot.rr.com/graye/Articles/SavingDataADO.htm.   The downloadable samples at these articles are small and directly to the point (so you wont' have to wade thru thousands of lines of code....sorry about that)
0
 
grayeCommented:
I believe you're thinking too hard...

The whole idea of using a strongly-typed dataset is to simplify the interfaces to ADO.Net.   This strongly-typed dataset is generated by the MSDataSetGenerator from an XML-based schema file (an XSD file).   So, intead of using the ADO.net syntax of:

          ds.Tables("Customers")

you'd use

         ds.Customers

We wont be able to provide you an exact sample, because your scheme defines the dataset (and would be different from our examples)

I've got a program (written in VB.Net) that uses a strongly-typed dataset in just the same way as you describe... there is no database envolved (er, well... at least not at the beginning).   The program adds data, produces reports, prints, saves/retrieves the data into an XML file, etc.

You're welcome to take a look at it if you wish:  http://home.hot.rr.com/graye/Articles/SOSOS.htm

0
 
mlazearAuthor Commented:
graye,

Thank you for the access to your project.

I downloaded the SOSOS project and am looking thru that.  It looks like you skipped the MSDatasetGenerator and just wrote the XML serialization code yourself.  Is that correct?  Any particular files I should be checking out in this project?

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
grayeCommented:
No, not exactly...    I built the DataSet using the XSD designer (not by doing a drag-n-drop operation from a database server).   But the translation from SOSOSDataSet.xsd file to the SOSOSDataSet.vb file is all done by the MSDataSetGenerator.   You'll notice there are no TableAdapters, since I'm not using a backend database server.

Sorry, that is a *huge* project to use as an example, but it has a little bit of everything.

saving the DataSet to an XML file (fmMain.vb, line 979, tsmiDataExportSchema_Click)
reading an XML file into the DataSet (fmMain.vb, line 923, tsmiDataImport_Click)
adding new row appears everywhere in the snoop.vb file, but a simple example is at line 378

Creating an instance of the SOSOSDataSet class is just as easy as any other class, for example:
    Private ds As New SOSOSDataSet
0
 
mlazearAuthor Commented:
The reason I thought you didn't use the MSDataSetGenerator was the SOSOSDataSet.vb module had no code it in.  I now realize there was a module underneath that SOSOSDataSet.designer.vb that does have the code.  

I can see how to read the XML in and write the XML out since that is just one call in each case.  It's the populating the fields within the XML data the first time and then getting to the data that I'm not sure about.

For example in your XSD file you have Accounts.  If I wanted to set the values of that record and store it in ds which is of type SOSOSDataSet.  I'm not sure of the steps.  I know there are rows and I make some call to create a row and then access the fields in that record.  The designer.vb file is good size and there is no document that says "here do this to create a record".  I realize the actual name of subroutines is different depending on how the XSD file is laid out thus I was not expecting exact code since I haven't uploaded my XSD file.

I used an XML Schema file rather than a DataSet file so the Designer is a bit different.  In my case I have a complex type record that contains a few other complex type records.  There will only be one record of each in the XML file.

I have to run now but I'll take a look at the code lines you suggested and see if that answers my question.  If my further description prompts any easier description of what I should be doing I would appreciate it.

Thanks for your help.


0
 
mlazearAuthor Commented:
Actually, I've never used ADO.NET so I had nothing to compare to.  I guess if I had written ADO.NET programs then switching them to use the strongly type files would not be a problem.   In my case I'm not trying to anything with ADO.NET.  I'm simply trying to use the XSD to layout a file format that has a couple hundred fields.  Then using the MSDataSetGenerator I let VS generate the VB code so I don't have to create the class with the serialization and all of the property functions manually.  

Since I've not used this before I wasn't sure the sequence of calls I needed to make in order to simply create a record.

I've got a meeting to run off to for a few hours, when I get back I will try out the "new way".  I think that's exactly what I was looking for.

I will also take a look at the articles suggested.  

I really do appreciate your help and I think that I have what I need but I'll confirm that later today.
0
 
mlazearAuthor Commented:
Dim dr As SOSOSDataset.AccountsRow = ds.Accounts.NewAccountsRow
dr.ID_Account = 12
dr.Account = "Some Name"
ds.Accounts.AddAccountsRow(dr)

The above steps did the trick and was exactly what I was looking for.  In particular the ds.Accounts.NewAccountsRow was the missing piece I couldn't find.  I didn't realize the class procedures were similar to the ADO.NET class (NewRow versus NewAccountsRow) which is why I was looking for a document that described how to use the code created by MSDatasetGenerator and why I was confused when you kept bringing up ADO.NET since I'm just trying to create an XML file.  
Though I can see now why you did.

Thanks a bunch!
0
 
mlazearAuthor Commented:
I really appreciate you sticking with it on this question.
0
All Courses

From novice to tech pro — start learning today.