Monday, March 12, 2012

How to convert Class object into DataSet?

Lets say, I have a following XSD utility generated class as follows:

[XmlRoot(Namespace="http://example.com/2007/ex1")]
public class Example {
public Example () {}
public string Name;
public int Power;
}

I have to pull data from several tables(MS Access2003) and store it in a DataSet.

Now, Is it possible to use it like:

Example example = new Example();
example.Power = 42;
example.Name = "Kibo";
DataSet myDataSet = new DataSet();
myDataSet = example;

or

myDataSet.Add(example);

Somehow, to add the example object tree in myDataSet, and pull values from tables directly into myDataSet.

This will help me in doing following things:

1. I'd not need to change my existing XSD generated class structure into DataSet.

2. Pull data directly into the DataSet, using explicit queries

3. Generate the Xml file directly.

Any help/idea/pointer/etc would help Alot.

Thanks.

The sample code you have given shouldn't work cause a DataSet can't load data from an custom entity object.

Check this site for more details:

http://msdn2.microsoft.com/en-us/library/ekw4dh3f(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/ekw4dh3f(VS.80).aspx

Labels: , , , , , , , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home