In. Net strange SQL query statements

Source: Internet
Author: User

When I write an SQL query statement in a program recently

I found a strange problem:

Select * Form tablename where name = '"+ textbox1.text + "'"

Sometimes, there is no problem in running.

However, sometimes problems occur.

For example, the content of textbox1.text is AAA

By program, all records meeting name = aaa should be queried.

(Here I want to declare that the database absolutely has a name = aaa record)

However, unexpectedly, after the program runs

No result is displayed (meaning no result is found)

At that time, I was dizzy.

Later, I rummaged over some materials. I had to do this:

Select * Form tablename where name = N' "+ textbox1.text + "'"

The program can get the desired results no matter how it runs!

[In fact, although the requirements have been met, I still don't understand why "N" must be added.]

I wanted to send my post to my experience zone, but I thought about it later.

Maybe someone in the same industry has encountered a cainiao-level problem like me.

It is hard to understand theoretically

So let's use it on the homepage. Maybe someone else can give me some advice!

Dudu, sorry.

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.