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.