By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

XML into datagrid

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Mar 29 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Darin wrote:
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

*** Sent via Developersdex http://www.developersdex.com ***

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
Mar 29 '06 #2

P: n/a
What about the dataadaptor part, which then has the da.fill(ds,"Sheet")?

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Mar 29 '06 #3

P: n/a
Chris wrote:
Darin wrote:
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

*** Sent via Developersdex http://www.developersdex.com ***


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
Mar 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.