Creating ADO.NET DataSet definition files, C#

Hello,

I do reporting solutions, VS2005,C#, SQL Server 2005. I am looking for a way to set up a typed ADO.NET DataSet definition reference before actually generating a DataSet. I heard it can be done thru a C# Class, XML Schema .xsd file, etc. What options do I have

Thanks,

Serge



Answer this question

Creating ADO.NET DataSet definition files, C#

  • smalamas

    Serge,

    I'd recommend running the xsd.exe tool from your system, if possible. You will have to persist your XSD file, but if you're constructing it memory, it shouldn't be too bad to save it to disk. Once you have the .xsd file, call out to xsd.exe, and then move the created Typed DataSet file to where you need it. Should that work for your situation

    Erick


  • Austink

    Serge,

    You create the schema at run-time, via an Xml object, correct At this point, what are you going to be doing with your TypedDataSet Are you only using it in memory, or do you need to generate the source code for the DataSet and persist it to storage

    Erick


  • manders

    Serge,

    That depends on what type of application it is. If it's a windows client application, you can use System.Diagnostics.Process to start xsd.exe. If you are on a system like a web server, or where you don't have access to the file system, you can directly use the Typed DataSet code generator. However, this is not a trivial task, and if you can use xsd.exe, I would highly recommend it. xsd.exe can run under a normal account, so I think that this is really the way to go.

    Erick


  • Kevin Zhang

    Hey Erick,

    the trick here is to design the XSD schema at run when the user selects the server, DB, table and finally the fields, you know like the visual designer but thru an app's GUI . I want to have the reference to such custom designed dataset to be used later on when the data are needed for further processing.

    Thanks,

    Serge


  • Dunia

    Serge,

    I see what you are trying to do now. There are a number of ways you could create the Typed DataSet schema at runtime. The easiest way is probably going to be to create an untyped DataSet with the same structure as you want, then use the DataSet.GetXmlSchema method to return the schema. Then, you can save this into an XSD file and run xsd.exe on it.

    Erick


  • Mark Guenault

    Hey Erick,

    I am not sure I follow you. What you are suggesting is I use xsd.exe to generate a typed DataSet Class file, .cs file in my case as I use C#. But I need to have a valid .xsd schema file to pass it to xsd.exe as a parameter. So I will have to use the VS2005 Dataset visual designer first to get the schema file.

    My goal is avoid design time and allow to do everything at run. I need to find a way to enable the creation/persisting to memory of a typed DataSet from GUI of my app. Further, I want the user to be able to reference the previously created library of typed datasets to access the tables and fields they hold to define and create tabular reports

    Hope this helped,

    Serge


  • Tin Aung Soe

    Hi Erick,

    Yes, I want to store the resulted DataSet Class so that I could use it in my report building tool later on. At one of the steps I will give the user a chance to choose among Available Data Sources so that the needed tables could be selected. "ADO.NET DataSets" will be one of the list items that will, I hope, have the DataSet Class created using the XSD Schema.

    So, we have created all objects at run - the schema and the corresponding dataset class. With the right GUI the user have it all customized and can reference the Class used to obtain data the user needs.

    Hope this helped :)

    Serge


  • Worf

    Serge,

    You can create the Typed DataSet class using either the visual designer in Visual Studio, or using the xsd.exe tool from the command line. Both of these options use an XSD schema file to define the structure of the DataSet.

    Erick


  • Lian6006

    Thanks Erick,

    how would you suggest I run xsd.exe at run Shell or there's a CLR class to do it

    Thanks,

    Serge


  • spenopolis

    Thanks a lot Erick,

    Have a nice weekend!

    Serge


  • Creating ADO.NET DataSet definition files, C#