xmldatareader?


B

bic

Hi,

Within .NET Framework there is System.Data.SqlClient namespace and within
that there is SqlDataReader object that has a read method. As shown in the
code this read method can read in desired dataset and store it in a control
and display it. Instead of SQL Server data I am dealing with XML data file
and with XSL formatter and would like to know a compable way of reading in
desired XML data or nodes. Thanks

-----SQLreader--------

Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyReader As SqlDataReader
Dim CT1 As String
Dim CaseTrackConnectionString As String
CaseTrackConnectionString =
ConfigurationManager.ConnectionStrings("CollectionConnectionString").ConnectionString
MyConnection = New SqlConnection(CaseTrackConnectionString)
MyCommand = New SqlCommand
CT1 = "SELECT * FROM Driver WHERE DriverID='" +
DriverDropDownList.SelectedValue.ToString + "'"
MyCommand.CommandText = CT1
MyCommand.CommandType = CommandType.Text
MyCommand.Connection = MyConnection
MyCommand.Connection.Open()
MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)
While MyReader.Read()
If MyReader("DriverMobile") IsNot System.DBNull.Value Then
DriverMobileLabel.Text = MyReader("DriverMobile")
EndIf

EndWhile
MyCommand.Dispose()
MyConnection.Close()
MyConnection.Dispose()
 
Ad

Advertisements

B

bic

Mark,
Thanks for the prompt reply. I saw in your referenced sample code only has
a XML file but has no XSL stylesheet file and wonder what I need to do
differently. Below is my xsl file which transform xml file into a subset, and
it also converts elements into attributes and sets a key.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"<xsl:blush:utput method="xml" indent="yes"/>
hotelId
<xsl:key name="hotelId-key" match="Hotel" use="hotelId"/>
<xsl:template match="HotelAvailabilityListResults">
<HotelAvailabilityListResults>
<xsl:apply-templates select="Hotel"/>
</HotelAvailabilityListResults>
</xsl:template>

<xsl:template match="Hotel">
<xsl:copy>
<xsl:copy-of select="name | address1 | city | stateProvince | country |
postalCode | shortDescription | HotelProperty/RateInfo"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


Thanks,
 
B

bic

Mark,

Since I have a xsl stylesheet for transformation, I take it I can first
transform it to another xml file and then follow your suggested method.
Correct?
 
Ad

Advertisements

B

bic

can you show me some code for returning FirstName and LastName based on
employeeID
i.e. SELECT * FROM employee WHERE employeeId=1 from the following xml file

<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee>
<EmployeeId>1</EmployeeId>
<FirstName>Tom</FirstName>
<LastName>Jones</LastName>
</Employee>
<Employee>
<EmployeeId>2</EmployeeId>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Employee>
</Employees>

Thanks,
 

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

Similar Threads


Top