Be careful when using datatable. Select

Source: Internet
Author: User
Recently in the blog Code During the reconstruction, I found that it is quite convenient to use able. Select to query XML data.
For example, we can query the data of the corresponding node in XML data based on the parameter values in the URL.
Suppose we have such an XML data file catalog. xml: < Navigation >
< Catalog Title = "Non-technical Zone" URL = "Default. aspx? Cate = 2" RSS = "Mainfeed. aspx? Cate = 2" Visible = "True" Cate = "2" />
< Catalog Title = "Reprinted area" URL = "Default. aspx? Cate = 7" RSS = "Mainfeed. aspx? Cate = 7" Visible = "True" Cate = "7" />
</ Navigation >

You can use datatable. Select to query XML data by using the following methods: Dataset myds = New Dataset ();
Myds. readxml ( " Catalog. xml " );
If (Request. querystring [ " Cate " ] ! = Null )
{
Querystr="Cate ="+Request. querystring ["Cate"];
}

Datarow [] row = Myds. Tables [ 0 ]. Select (querystr );
  If (Row. Length > 0 )
{
URL=Row [0] ["URL"]. Tostring ();
}

at first, I used the above method to query the correct results, but when the catalog. when the Cate of a node in XML is greater than 10, for example, Cate = 10. tables [0]. select ("Cate = 10") cannot query nodes with Cate = 10. At first, I was puzzled because I think Cate is processed as an int type in myds. Later, I thought about whether dataset treats cate as a string when the Cate turns to a double-digit number? I changed the code to
querystr = "Cate = '" + request. querystring ["Cate"] + "'";
the problem is solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.