Solved

Createing a dataset using and XSD

Posted on 2011-02-16
7
1,188 Views
Last Modified: 2012-05-11
Hi there everyone,

I'm now trying to figure out how to create a dataset from the XSD so that I can load it. I've run the XSD.exe and it created the resulting vb extension. I've imported that into the project and it ended up as part of the XSD. But when I try to refer to it in my program, intellisence doesn't recognize the xsd as a dataset.

The long term goal here is to be able to fill the dataset and then do a 'writexml' out of that dataset.

Any suggestions would be greatly appreciated. Thanks! - Eric -
0
Comment
Question by:carpetking
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34921757
I am confused about your question, and the ultimate goal.  Are you working with a typed DataSet or a non-typed DataSet?
0
 

Author Comment

by:carpetking
ID: 34921842
Well, I can understand partially your confusion. The title should have read...

"Creating a dataset using an XSD"

In other words, I want to create a dataset based on an XSD that I received from a government agency. I will then populate the dataset based on the contents from a series of data tabels. After the dataset is populated I want to the do a getxml (or writexml) to get the resulted XML outof the dataset.

My end result is to get xml data that is in the format of the XSD that was provided to my by the state agency.

Does that make more sence or is it still clear as mud?

Thanks for your help! - Eric -
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34922880
Eric, I believe that you are saying that you want to use the XSD schema as a basis for creating another DataSet object with the same schema, which is described in this article:

How Do I...Create DataSet mappings from an XSD schema?
http://authors.aspalliance.com/quickstart/howto/doc/Xml%5CDataSetMapXSDSchema.aspx

The DataSet class has a close affiliation with the XmlDataDocument class. The DataSet class provides a relational view of the XML data loaded through the XmlDataDocument. To build a relational mapping between these two views, you need to use the ReadXmlSchema method of the DataSet. You use this method when you create the XmlDataDocument as in the following call, XmlDataDocument.DataSet.ReadXmlSchema. Now, any changes made to the DataSet are reflected in the XmlDataDocument and vice versa.

Let me know if that is what you are talking about...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:carpetking
ID: 34927758
Hi there TheLearnedOne,

Thank you so much for the response. You understood what I was trying to get at perfectly. Also, I think you have found the solution, but I'm not able to get to the source code on the internet. It looks like the link is broken. I was able to get to the meat of the solution though based on what is shown in the article. My program is blowing up, probably because I don't have all of the correct code implemented. I'll keep slugging away at it to see if I can get it figured out. If you know of some place else that I can download the entire solution, please let me know.

If not, don't worry about it, I'll keep plugging away and mark your last response as the solution.

Thanks again so much for your help! - Eric-
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 34927822
To illustrate this relationship, the following sample code reads and loads the books.xsd schema file into the DataSet property on an XmlDataDocument. Notice how the ReadXmlSchema method takes the schema loaded into a StreamReader and generates the relational mappings. If there is already a relational view defined in the XmlDataDocument, the sample throws an exception.

Dim myStreamReader as StreamReader = nothing
try
    myStreamReader = new StreamReader(schema)
    Console.WriteLine("Reading Schema file ...")
    myXmlDataDocument.ReadXmlSchema(myStreamReader)
catch e as exception
    Console.WriteLine ("Exception: " & e.ToString())
finally
    If Not myStreamReader Is Nothing
        myStreamReader.Close()
    end if
end try

Open in new window


So how do you know what the internal tables generated from the schema look like? Well, the DataSet has a Tables property that is a collection of the internal tables. Each table has a Columns collection and each column has a ColumnName and a DataType. You can simply iterate over these collections and format the output to display the internal table structure built from the supplied schema, as shown in the following code.

 Displays the DataSet tables structure
private sub DisplayTableStructure()
    Console.WriteLine()
    Console.WriteLine("Table structure")
    Console.WriteLine()
    Console.WriteLine("Tables count=" & myXmlDataDocument.Tables.Count.ToString())

    Dim i,j as integer

    for i = 0 to (myXmlDataDocument.Tables.Count - 1)
        Console.WriteLine("TableName='" & myXmlDataDocument.Tables(i).TableName & "'.")
        Console.WriteLine("Columns count=" & myXmlDataDocument.Tables(i).Columns.Count.ToString())

        for j = 0 to (myXmlDataDocument.Tables(i).Columns.Count - 1)
            Console.WriteLine(Strings.chr(9) & "ColumnName='" & _
                              myXmlDataDocument.Tables(i).Columns(j).ColumnName & _"', type = " & _
                              myXmlDataDocument.Tables(i).Columns(j).DataType.ToString())
        next
        Console.WriteLine()
    next
end sub

Open in new window


The following output shows the table names, column names, and the column types displayed by the DisplayTableStructure method for the books.xsd schema.


Table structure

Tables count=3
      TableName='bookstore'.
      Columns count=1
            ColumnName='bookstore_Id', type = System.Int32
      TableName='book'.
      Columns count=5
            ColumnName='title', type = System.String
            ColumnName='price', type = System.Decimal
            ColumnName='genre', type = System.String
            ColumnName='book_Id', type = System.Int32
            ColumnName='bookstore_Id', type = System.Int32
      TableName='author'.
      Columns count=3
            ColumnName='first-name', type = System.String
            ColumnName='last-name', type = System.String
            ColumnName='book_Id', type = System.Int32

0
 

Author Comment

by:carpetking
ID: 34927884
TheLearnedOne!

I figured it out... the problem with my program was that I didn't define a 'New' dataset in my DIM statement. It turns out that the schema from the state agency has some custom stuff in it that the Streamreader doesn't understand. so, I'll have to deal with that Manually.

None the less, I appreciate all of your help! You are the best! - Eric -
0
 

Author Closing Comment

by:carpetking
ID: 34927887
Thanks for all of the help!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now