Connecting Tech Pros Worldwide Forums | Help | Site Map

Treat a DataSet as a class structure

SteveT
Guest
 
Posts: n/a
#1: Oct 3 '06
Can someone point me in the right direction? Somewhere I read that you
reference a strongly typed dataset as if it were a class structure. For
example,

<SomeTests>
<TestsGroups>
<Group>
<TestName>TestA</TestNmae>
<Test>Run1</Test>
<Test>Run2</Test>
<Test>Run3</Test>
</Group>
</TestsGroups>
</SomeTests>

I want to reference this like SomeTest.TestGroups.Group.Test[a]. Is this
possible?
--
-----------
Thanks,
Steve
Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Oct 3 '06

re: Treat a DataSet as a class structure


Steve,

Have you created this in the data set designer? You can add a new data
set to your project and then design it so that it mimics this structure.
Then, you should be able to access it in your code with strongly typed
accessors.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"SteveT" <SteveT@newsgroups.nospamwrote in message
news:E3BB6F72-66EE-4072-86C3-254EDB1419F6@microsoft.com...
Quote:
Can someone point me in the right direction? Somewhere I read that you
reference a strongly typed dataset as if it were a class structure. For
example,
>
<SomeTests>
<TestsGroups>
<Group>
<TestName>TestA</TestNmae>
<Test>Run1</Test>
<Test>Run2</Test>
<Test>Run3</Test>
</Group>
</TestsGroups>
</SomeTests>
>
I want to reference this like SomeTest.TestGroups.Group.Test[a]. Is this
possible?
--
-----------
Thanks,
Steve

Spam Catcher
Guest
 
Posts: n/a
#3: Oct 3 '06

re: Treat a DataSet as a class structure


=?Utf-8?B?U3RldmVU?= <SteveT@newsgroups.nospamwrote in
news:E3BB6F72-66EE-4072-86C3-254EDB1419F6@microsoft.com:
Quote:
Can someone point me in the right direction? Somewhere I read that
you reference a strongly typed dataset as if it were a class
structure. For example,

..NET has built in support for Typed Dataset.

http://www.15seconds.com/issue/031223.htm

However, also take a look at OR/M tools such as LLBLGen Pro and .NET teirs
- they're much more flexible (and MUCH more powerful).
SteveT
Guest
 
Posts: n/a
#4: Oct 3 '06

re: Treat a DataSet as a class structure


Is there some example that walks one through how to do this done in the
designer with a XML / XSD file? I don't want to use a "database" and the
Designer seems to be written with that in mind. Once the DataSet is created,
will my dataset simple allow me to reference the contents as if it were the
DataSet?
--
-----------
Thanks,
Steve


"Nicholas Paldino [.NET/C# MVP]" wrote:
Quote:
Steve,
>
Have you created this in the data set designer? You can add a new data
set to your project and then design it so that it mimics this structure.
Then, you should be able to access it in your code with strongly typed
accessors.
>
Hope this helps.
>
>
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>
"SteveT" <SteveT@newsgroups.nospamwrote in message
news:E3BB6F72-66EE-4072-86C3-254EDB1419F6@microsoft.com...
Quote:
Can someone point me in the right direction? Somewhere I read that you
reference a strongly typed dataset as if it were a class structure. For
example,

<SomeTests>
<TestsGroups>
<Group>
<TestName>TestA</TestNmae>
<Test>Run1</Test>
<Test>Run2</Test>
<Test>Run3</Test>
</Group>
</TestsGroups>
</SomeTests>

I want to reference this like SomeTest.TestGroups.Group.Test[a]. Is this
possible?
--
-----------
Thanks,
Steve
>
>
>
SteveT
Guest
 
Posts: n/a
#5: Oct 3 '06

re: Treat a DataSet as a class structure


Nicholas,

I've been reading up on this DataSet Designer. Do I need it or the XML
Designer to create the Schema that my code will understand? In the DataSet
Designer it looks like I have to use primary keys, but I don't want to. I
just want a nested relationship like the example I showed. Can the DataSet
Designer do this? Also, how to I create an XML file from the XSD file
created from the DataSet Designer. I know how to do it from the XML
Designer, but I've not used the DataSet Designer before.

--
-----------
Thanks,
Steve


"Nicholas Paldino [.NET/C# MVP]" wrote:
Quote:
Steve,
>
Have you created this in the data set designer? You can add a new data
set to your project and then design it so that it mimics this structure.
Then, you should be able to access it in your code with strongly typed
accessors.
>
Hope this helps.
>
>
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>
"SteveT" <SteveT@newsgroups.nospamwrote in message
news:E3BB6F72-66EE-4072-86C3-254EDB1419F6@microsoft.com...
Quote:
Can someone point me in the right direction? Somewhere I read that you
reference a strongly typed dataset as if it were a class structure. For
example,

<SomeTests>
<TestsGroups>
<Group>
<TestName>TestA</TestNmae>
<Test>Run1</Test>
<Test>Run2</Test>
<Test>Run3</Test>
</Group>
</TestsGroups>
</SomeTests>

I want to reference this like SomeTest.TestGroups.Group.Test[a]. Is this
possible?
--
-----------
Thanks,
Steve
>
>
>
Luke Zhang [MSFT]
Guest
 
Posts: n/a
#6: Oct 4 '06

re: Treat a DataSet as a class structure


Hello Steve,

To generate a XML file from XSD file created in DataSet designer, we need
create a dataset object, fill in data and use its WriteXml() method to
generate the XML data.

Also you can read XML data directly into a dataset, for example, test.xml:

<SomeTests>
<TestsGroups>
<Group TestName="TestA" >
<Test>Run1</Test>
<Test>Run2</Test>
<Test>Run3</Test>
</Group>
</TestsGroups>
</SomeTests>


(Your original XML is not valid for a dataset, so I modify a little)

DataSet ds = new DataSet();
ds.ReadXml("c:\\test.xml");

foreach (DataTable dt in ds.Tables)
{

System.Diagnostics.Debug.WriteLine(dt.TableName);
}

We will get three tables in the dataset; TestsGroup, Group and Test.
Anyway, this is not a strong typed dataset. To create a strong type
dataset, you need to create the schema in the dataset designer.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



SteveT
Guest
 
Posts: n/a
#7: Oct 4 '06

re: Treat a DataSet as a class structure


I appreciate yours and everyone elses responses. Each has helped me get a
little further.

I'm now able to create and populate my XML and XSD files correctly. I can
even see the XSD "class structure" within my program now. However, I can't
figure out how to treat my dataset that is read in
(myDataSet.ReadXml(filename)) as a class structure.

I've tried SomeTests.TestGroupsDataTable table = new
SomeTests.TestGroupsDataTable((DataTable)myDataSet .Tables["Group"]) but this
only gives me a null table.

How do I reference the dataset as if it were a class structure?
--
-----------
Thanks,
Steve


"Luke Zhang [MSFT]" wrote:
Quote:
Hello Steve,
>
To generate a XML file from XSD file created in DataSet designer, we need
create a dataset object, fill in data and use its WriteXml() method to
generate the XML data.
>
Also you can read XML data directly into a dataset, for example, test.xml:
>
<SomeTests>
<TestsGroups>
<Group TestName="TestA" >
<Test>Run1</Test>
<Test>Run2</Test>
<Test>Run3</Test>
</Group>
</TestsGroups>
</SomeTests>
>
>
(Your original XML is not valid for a dataset, so I modify a little)
>
DataSet ds = new DataSet();
ds.ReadXml("c:\\test.xml");
>
foreach (DataTable dt in ds.Tables)
{
>
System.Diagnostics.Debug.WriteLine(dt.TableName);
}
>
We will get three tables in the dataset; TestsGroup, Group and Test.
Anyway, this is not a strong typed dataset. To create a strong type
dataset, you need to create the schema in the dataset designer.
>
Sincerely,
>
Luke Zhang
>
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
>
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
>
This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
Luke Zhang [MSFT]
Guest
 
Posts: n/a
#8: Oct 5 '06

re: Treat a DataSet as a class structure


Normally, after we define Dataset and Datatable, we can create a new
datatable as:

DataSet1.DataTable1DataTable dt= new
DataSet1.DataTable1DataTable(SomeDataTable);

From your code

SomeTests.TestGroupsDataTable table = new
SomeTests.TestGroupsDataTable((DataTable)myDataSet .Tables["Group"])

Have you check the myDataSet.Tables["Group"] contians actual records, and
its schema exactly match with SomeTests.TestGroupsDataTable?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



Closed Thread


Similar C# / C Sharp bytes