XML into datagrid

D

Darin

I can get an XML loaded into a datagrid using:

Dim ds As New DataSet
ds.ReadXml("jp.xml")
gData.DataSource = ds

But, this a grid that allows clicking on the plus to see styles,
alignment, etc.

I want to load it in a datagrid so it appears in rows and columns just
like if I were to load a CSV file using:

Dim tmpConnection As New
System.Data.OleDb.OleDbConnection(DDIConnectString("test.csv"))
tmpConnection.Open()

strsql = "SELECT * FROM test.csv"
Dim da As New System.Data.OleDb.OleDbDataAdapter(strsql, tmpConnection)
Dim ds As New DataSet("Workbook")
Dim dt As DataTable
Dim drRow As DataRow

da.Fill(ds, "Sheet1")
dt = ds.Tables("Sheet1")
gData.DataSource = dt
tmpConnection.Close()

Thanks.

Darin
 
C

Chris

Darin said:
I can get an XML loaded into a datagrid using:

Dim ds As New DataSet
ds.ReadXml("jp.xml")
gData.DataSource = ds

But, this a grid that allows clicking on the plus to see styles,
alignment, etc.

I want to load it in a datagrid so it appears in rows and columns just
like if I were to load a CSV file using:

Dim tmpConnection As New
System.Data.OleDb.OleDbConnection(DDIConnectString("test.csv"))
tmpConnection.Open()

strsql = "SELECT * FROM test.csv"
Dim da As New System.Data.OleDb.OleDbDataAdapter(strsql, tmpConnection)
Dim ds As New DataSet("Workbook")
Dim dt As DataTable
Dim drRow As DataRow

da.Fill(ds, "Sheet1")
dt = ds.Tables("Sheet1")
gData.DataSource = dt
tmpConnection.Close()

Thanks.

Darin


You have the answer to your problem in your code.

In the first one you assign a DataSet to the datagrid
ds.ReadXml("jp.xml")
gData.DataSource = ds

In the second one you assign a DataTable to the datagrid
da.Fill(ds, "Sheet1")
dt = ds.Tables("Sheet1")

So if you assign the DataTable that is in the dataset, you will get the
result you are looking for.

Chris
 
C

Chris

Chris said:
You have the answer to your problem in your code.

In the first one you assign a DataSet to the datagrid
ds.ReadXml("jp.xml")
gData.DataSource = ds

In the second one you assign a DataTable to the datagrid
da.Fill(ds, "Sheet1")
dt = ds.Tables("Sheet1")

So if you assign the DataTable that is in the dataset, you will get the
result you are looking for.

Chris

That is just loading your DataSet. The ds.ReadXml does it in your first
example. Just bind the DataSet.Table(0) to your datagrid, you should be
good.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top