XML and Dataset problem

knappster

Active member
Joined
Nov 13, 2006
Messages
42
Programming Experience
Beginner
Hi,
I have an xml file that I want to load into a dataset in Visual Studio 2008 that looks like -
HTML:
<MyData>
	<Employee>
		<Name></Name>
		<DOB></DOB>
		<Address></Address>
	</Employee>
</MyData>
If I simply create a dataset in code and call the ReadXML() method, it works as planned and the data is loaded. However, I want to design the dataset visually, creating a .xsd file in VS. I do this and add a DataTable called Employee and three columns the same names as above. If I do this then call the ReadXML() method on this dataset, there is never any data loaded. What am I doing wrong?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,412
Location
Norway
Programming Experience
10+
When you add a new Dataset a default namespace is set, for example http://tempuri.org/DataSet1.xsd. Your data does not have this namespace, so change it to an empty string. Do this by opening the Dataset Designer and click the background, then make the change in Properties window.

You can also save time by using the Xsd.exe tool to generate the dataset from your existing data, then adding this dataset to the project (Add Existing...). Running the command "xsd data.xml" from Visual Studio prompt generates the "data.xsd" dataset schema.
 

knappster

Active member
Joined
Nov 13, 2006
Messages
42
Programming Experience
Beginner
That's excellent, worked like a charm, didn't have a clue about the namespace property! Also that XSD.exe tool was brilliant, saved me a lot of typing!
Cheers for your help...
 
Top Bottom