Populate datagrid from XML file using where type query

G

gn

I am able to populate a datagrid from an XML variable using the
following:

Try
Dim ds As New DataSet
ds.ReadXml(New
StringReader(HttpContext.Current.Application("var").ToString))
dataMeet.DataSource = ds
dataMeet.DataBind()
Catch ex As Exception
error_email.fncErrorHandler(ex)
lblError.Text = ex.ToString
End Try

however this does not allow me to use a sql type query to select
exactly the data I want in the datagrid.

The query I am looking to achieve is actually very simple, just a
simple 'where' but I have no idea how to achieve this when binding to
an xml variable

The sql query and a sample xml file are pasted below:

select TITLE, FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME, DEPT, EMAIL,
PHONE FROM DATABASE.TABLE "
WHERE MEMBERTYPE_CODE = 'MEM' ORDER BY MEMBER_ID

<NewDataSet>
<Table>
<MEMBERTYPE_CODE>OFF</MEMBERTYPE_CODE>
<LAST_NAME>Smith</LAST_NAME>
<FIRST_NAME>Harry</FIRST_NAME>
<TITLE>engineer</TITLE>
<DEPT>engineering</DEPT>
<EMAIL>[email protected]</EMAIL>
<PHONE>(111) 111-1111</PHONE>
</Table>
<Table>
<MEMBERTYPE_CODE>MEM</MEMBERTYPE_CODE>
<LAST_NAME>fred</LAST_NAME>
<FIRST_NAME>bloggs</FIRST_NAME>
<TITLE>Webmaster</TITLE>
<DEPT>Information Technology Services</DEPT>
<EMAIL>[email protected]</EMAIL>
<PHONE>(111) 111-1112</PHONE>
</Table>
</NewDataSet>

Thank you for your time
 
E

Elton Wang

Hi gn,

You can use DataView's properties RowFilter and Sort to
perform functionality similar to 'WHERE' condition
and 'ORDER BY' in sql query. Following is sample code
snippet:

Dim dv As DataView = ds.Tables(0).DefaultView
dv.RowFilter = "MEMBERTYPE_CODE = 'MEM'"
dv.Sort = "LAST_NAME"
dataMeet.DataSource = dv
dataMeet.DataBind()

HTH

Elton Wang
(e-mail address removed)
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top