Note ADO. The symbol format in the data query statement in net (C # Implementation)

Source: Internet
Author: User
Tags date
ado| Data | statement

1, the use of wildcard characters

In ADO. NET allows you to use wildcard characters for data queries. As in the following statement query table EmployeeID All data starting with a
Select employeeid,employname,tel,salary ... where employeeid= ' a% ';

Ado. NET allows% or * wildcard characters to be used at the beginning or end of a string. such as the following statement to query the table all the number of numbers in the tail of the document s
Select productcode,productname,productsum,productprice ... where ordercode= '%s '

Ado. NET does not allow the use of separate symbols such as "?", "-" and so on

2, the use of separators
A. Quotes
Be aware of the use of single quotes in ado.net, for example, when querying for a user's name, the user may look for data with the name K ' Leey, at which point the data query statement becomes
Name= ' K ' leey '
When single quotes appear when you query, it should be replaced with two single quotes, that is, name= ' K ' leey ', in practice, when single quotes appear in a data query statement, you can substitute the Replace method of the string class with the "'", as
Condition = "Name= '" +tempname. Replace ("" "," "") + ""

B. Date
You can use the # symbol to process queries in ado.net that involve date formats, as shown in the following example
Condition = "enddate< #2005/09/07# and enddate> #2005/08/07#"

C. Column Separator
When a column in a datasheet contains a column separator for some reason, such as sale order, you can use [] to differentiate this column, as shown in the following example
condition = "[Sale order] = S845647"
In this case, if the data column already contains a column delimiter as part of the column name sale] order[, you need to add the \ symbol before the end of the column separator.
Condition = "[sale\] order[] = S845647"
If you are dealing with this ado.net operation in C #, you need to be aware of the symbolic escape problem, and the example will become
Condition = "[sale\\] order[] = S845647"




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.