[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

Createing a dataset using and XSD

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
carpetking
Asked:
carpetking
  • 4
  • 3
1 Solution
 
Bob LearnedCommented:
I am confused about your question, and the ultimate goal.  Are you working with a typed DataSet or a non-typed DataSet?
0
 
carpetkingAuthor Commented:
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
 
Bob LearnedCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
carpetkingAuthor Commented:
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
 
Bob LearnedCommented:
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
 
carpetkingAuthor Commented:
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
 
carpetkingAuthor Commented:
Thanks for all of the help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now