Solved

Createing a dataset using and XSD

Posted on 2011-02-16
7
1,182 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:carpetking
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for all of the help!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

8 Experts available now in Live!

Get 1:1 Help Now