none
Can I use xml schema to define a dataset table RRS feed

  • Question

  • I have a case where I have .xsd files that I want to use with the Dataset object in VB 2010.

    Can I use an .xsd file to create the column definitions for the DataTable object?

    I am trying to avoid re-typing all the column data and the risk of error doing so.

    Thanks.

    Murray


    M Whipps

    Thursday, July 18, 2013 10:50 PM

Answers

  • Hi Murray,

    Perhaps what you might want to think about is using a Typed DataSet ... they are generated from .xsd files in Visual Studio using the MSDataSetGenerator once you've added the .xsd to your project. Take a look at two of my blog posts:

    http://geek-goddess-bonnie.blogspot.com/2010/04/create-xsd.html

    Yes, I know that you already have the .xsd, but the above post also describes how to create the Typed DataSet from the .xsd.

    http://geek-goddess-bonnie.blogspot.com/2012/08/msdatasetgenerator-gone-wild.html

    The above post mentions a few "gotchas" that you've got to be careful with when using the MSDataSetGenerator.


    ~~Bonnie Berent DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, July 19, 2013 6:10 PM
  • Hi Murray,

    You can try to use DataTable.ReadXmlSchema() method to read the XML schema to the DataTable.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Friday, July 19, 2013 10:13 AM
    Moderator
  • Hi Murray,

    No, the only blog posts I've written about MSDataSetGenerator are those two. MSDataSetGenerator takes an .xsd and generates a Typed DataSet, which is exactly what you wanted to do, so you won't have to write any code at all. The only difference between a Typed DataSet and a "regular" DataSet is that your columns are Typed, so for example, an int column is actually an int! And your DataTables can be accessed by their TableNames. So, the syntax is slightly different, but much more readable and easier to use

    // non-typed syntax
    int CustomerID = Convert.ToInt32(MyDataSet.Tables["Customer"].Rows[0]["CustomerID"]);
    
    // typed syntax
    int MyID = MyDataSet.Customer[0].CustomerID;
    

    So give it a try, following the first blog post (you might have to type MSDataSetGenerator in the CustomTool property of the .xsd, from the Properties in the Solution Explorer). You might get a better understanding of Typed DataSets just by trying them out.


    ~~Bonnie Berent DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by 9gwcycn Wednesday, August 7, 2013 5:01 PM
    Wednesday, August 7, 2013 4:42 PM

All replies

  • Hi Murray,

    You can try to use DataTable.ReadXmlSchema() method to read the XML schema to the DataTable.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Friday, July 19, 2013 10:13 AM
    Moderator
  • Thanks for the link, Chester.

    Unfortunately the first step calls a function to create the table.

    Dim table As DataTable = CreateTestTable("XmlDemo")

    I want to create the table from the xsd to avoid the chance of error.


    M Whipps

    Friday, July 19, 2013 4:34 PM
  • Hi Murray,

    Perhaps what you might want to think about is using a Typed DataSet ... they are generated from .xsd files in Visual Studio using the MSDataSetGenerator once you've added the .xsd to your project. Take a look at two of my blog posts:

    http://geek-goddess-bonnie.blogspot.com/2010/04/create-xsd.html

    Yes, I know that you already have the .xsd, but the above post also describes how to create the Typed DataSet from the .xsd.

    http://geek-goddess-bonnie.blogspot.com/2012/08/msdatasetgenerator-gone-wild.html

    The above post mentions a few "gotchas" that you've got to be careful with when using the MSDataSetGenerator.


    ~~Bonnie Berent DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, July 19, 2013 6:10 PM
  • Hi Bonnie,

    I have read and re-read your posts and have decided that you're so far ahead of me that I cannot understand what it is you're discussing.

    I am a programmer with 25+ years experience in several languages but no deep knowledge of VS. Our product is written in VB 6. We are trying to move it into VS but all our data is kept in random-access files, and a lot of the file records use arrays which are impossible to implement in a Structure in VS so we're sort of scr...ed but that's another topic.

    I can't even find any reference that tells me what the MSDataSetGenerator  tool is, where it is, or what it does. VS help has nothing and BING searches produce lots garbage.

    Did you write a blog about what MSDataSetGenerator is?

    Thanks.

    Murray


    M Whipps

    Wednesday, August 7, 2013 3:31 PM
  • Hi Murray,

    No, the only blog posts I've written about MSDataSetGenerator are those two. MSDataSetGenerator takes an .xsd and generates a Typed DataSet, which is exactly what you wanted to do, so you won't have to write any code at all. The only difference between a Typed DataSet and a "regular" DataSet is that your columns are Typed, so for example, an int column is actually an int! And your DataTables can be accessed by their TableNames. So, the syntax is slightly different, but much more readable and easier to use

    // non-typed syntax
    int CustomerID = Convert.ToInt32(MyDataSet.Tables["Customer"].Rows[0]["CustomerID"]);
    
    // typed syntax
    int MyID = MyDataSet.Customer[0].CustomerID;
    

    So give it a try, following the first blog post (you might have to type MSDataSetGenerator in the CustomTool property of the .xsd, from the Properties in the Solution Explorer). You might get a better understanding of Typed DataSets just by trying them out.


    ~~Bonnie Berent DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by 9gwcycn Wednesday, August 7, 2013 5:01 PM
    Wednesday, August 7, 2013 4:42 PM
  • Thanks for your help Bonnie.

    M Whipps

    Wednesday, August 7, 2013 5:01 PM
  • You're welcome, Murray. Please let me know if you have any other questions! I'll be glad to help some more ...

    ~~Bonnie Berent DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, August 8, 2013 4:53 AM