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

DataTable.Select

P: n/a
Could someone please help me? I have searched everywhere
but couldn't find definite answers. I am trying to read
xml file to a dataset and select from it. Here's xml
file:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<data>
<id>1</id>
<name>Tae Lee</name>
</data>
<data>
<id>2</id>
<name>Tae Sung Lee</name>
</data>
</root>

Then here's the code.

Dim ds As New Data.DataSet
ds.ReadXml("data.xml")
Dim dt As DataTable = ds.Tables("data")
Dim str As String = "id = 2"
Dim dr As Data.DataRow = dt.Select(str)
Literal1.Text = dr.Item(1)

The problem is that when you select from datatable, the
result is 1-dimensional array of data row. So I get an
error when I attempt to put array into a row. If you
have any similar experience, please let me know. Thank
you so much.

-Tae Lee
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Tae Lee" <sq*******@hotmail.com> wrote in message
news:01****************************@phx.gbl...
Could someone please help me? I have searched everywhere
but couldn't find definite answers. I am trying to read
xml file to a dataset and select from it. Here's xml
file:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<data>
<id>1</id>
<name>Tae Lee</name>
</data>
<data>
<id>2</id>
<name>Tae Sung Lee</name>
</data>
</root>

Then here's the code.

Dim ds As New Data.DataSet
ds.ReadXml("data.xml")
Dim dt As DataTable = ds.Tables("data")
Dim str As String = "id = 2"
Dim dr As Data.DataRow = dt.Select(str)
Literal1.Text = dr.Item(1)

The problem is that when you select from datatable, the
result is 1-dimensional array of data row. So I get an
error when I attempt to put array into a row. If you
have any similar experience, please let me know. Thank
you so much.

-Tae Lee


If you assume that you are always returning exactly one result, then you can
do this:

Dim dr as Data.DataRow = dt.Select(str)(0)

Just make sure you are always getting back exactly one result!

Erik
Nov 20 '05 #2

P: n/a
Cor
Hi Tae,
Dim str As String = "id = 2"
Dim dr As Data.DataRow = dt.Select(str)
Literal1.Text = dr.Item(1)
It has to be a datarow collection and therefore Dim str As String = "id = 2"
Dim drcollection() As Data.DataRow = dt.Select(str) if drcollection.length > 0 then
dim dr as datarow = drcollection(0)
Literal1.Text = dr.Item(1)
'or if you wish literal1.text = drcollection(0)(1)
end if

I hope this helps?
Cor
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.