XML to Dataset to Datagridview

Clayton1234

Member
Joined
Jul 28, 2007
Messages
7
:eek:
Im trying to view an xml file with a datagrid view, and i get nothing..

I use dialog to get xml path
create a dataset
dataset.readxml(path)
datagridview.datasource = dataset


i dont know what else to try.
Please help :confused:
 
Here is a simple one I have. Hopefully this will help for what you are looking for or help to get you going in the right direction.
dtaEquip is my datagrid

Code:
     Try
            Dim strPath As String = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
            Dim dsEquip As New DataSet
            dsEquip.ReadXmlSchema(strPath & "HBLabSpec.xsd")
            dsEquip.ReadXml(strPath & "HBLabDevices.xml")
            Me.dtaEquip.DataSource = dsEquip.Tables("labdevice")
Catch ex As Exception
            MessageBox.Show(ex.Message, "Data Retrieval Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Here is what my xml file looks like.

Code:
<?xml version="1.0" standalone="yes"?>
<HBLabSpec xmlns="http://tempuri.org/HBLabSpec.xsd">
  <LabDevice>
    <Address>2</Address>
    <Device>xantrexps</Device>
  </LabDevice>
</HBLabSpec>
 
Would you mind explaining the two things ive quoted?

Dim strPath As String = AppDomain.CurrentDomain.SetupInformation.ApplicationBase




dsEquip.ReadXmlSchema(strPath & "HBLabSpec.xsd")


Thanks
 
The "Dim strPath..." statement gets the path to the directory from which the application is executing (which is obviously where he expects to find his XML data).

The "dsEquip.ReadXmlSchema..." statement gets the schema information for the XML file. A schema file describes the structure of an XML file. For instance, when you save a DataSet to an XML file using DataSet.WriteXml, with the XmlWriteMode.WriteSchema option, it will create a schema file for you that defines such things as: which nodes are the tables vs which nodes are the columns, etc. If you do not have a schema file, the DataSet.ReadXml method has to try to figure out the schema from the data. If unsuccessful, you either get an exception, or no data in the DataSet.

Todd
 
Can someone please help me build a schema for the following xml file???


___________________________
[highlight=xml]
<?xml version="1.0" ?>
<records>
<image signid="1309AB53-60F0-4678-82AA-F08C030E6E10">
<signtype>Aluminum Sign</signtype>
<signtypecustom />
<sizeheight>12</sizeheight>
<SizeWidth>16</SizeWidth>
<imagename>AAA0001.sef</imagename>
<computerid>AAA</computerid>
<datetimecreated>8/2/2007</datetimecreated>
<datetimesent>12:00:00 AM</datetimesent>
<noofcliparts>0</noofcliparts>
<noofobjects>2</noofobjects>
<isfromexistingart>0</isfromexistingart>
<firstname>cndjws</firstname>
<middlename>h</middlename>
<lastname>fhf</lastname>
<billaddress1>66 fggsd g</billaddress1>
<billaddress2 />
<billaddresscity>hdfhsh</billaddresscity>
<billaddressstate>al</billaddressstate>
<billaddresszip>36054</billaddresszip>
<shipaddress1>66 fggsd g</shipaddress1>
<shipaddress2 />
<shipaddresscity>hdfhsh</shipaddresscity>
<shipaddressstate>al</shipaddressstate>
<shipaddresszip>36054</shipaddresszip>
<billphoneno>3334444444</billphoneno>
<shipphoneno>3334444444</shipphoneno>
<altphoneno />
<emailaddress>gdfggad@tfsag.com</emailaddress>
<ccnumber />
<nameoncc />
<typeofcc />
<ccexpmonth>0</ccexpmonth>
<ccexpyear>0</ccexpyear>
<isreceiptprinted>0</isreceiptprinted>
<processingstatus />
<splinstructions />
<sentattempts>0</sentattempts>
<transmitsuccessimg />
<transmitsuccessxml />
<price>20.216</price>
<quantity>1</quantity>
<tshirtsize />
</image>
</records>
[/highlight]________________________
 
Last edited by a moderator:
This should be easier than you think actually. When you have your project opened, go to the xml file, right click on the page and scroll down where it says "Create Schema". And voila.
 
This should be easier than you think actually. When you have your project opened, go to the xml file, right click on the page and scroll down where it says "Create Schema". And voila.

I tried right clicking on the xml opened file, and i dont see "create schema"
 
I did a screen shot and attached a gif to see what I was talking about. I think I may know why you didnt see it. When you right clicked, did you do that on the file in the Solution Explorer area? That would not be where you would right click. You need to right click in the opened page, where the xml data is. Look at the pic and you will see what I mean.

But at least you found the button. I dont see the button, but I just looked and I dont have the toolbar for xml added.
 
Back
Top