When i use this string as a sql command-string compiler gives me no error:
当我使用此字符串作为sql命令字符串编译器给我没有错误:
string sql = "SELECT * FROM Students WHERE StudentNo='" + T_No.Text + "'";
But, if i use this string (includes '%' character) it says "Error converting data type varchar to bigint":
但是,如果我使用此字符串(包括'%'字符),则表示“将数据类型varchar转换为bigint时出错”:
string sql = "SELECT * FROM Students WHERE StudentNo='%" + T_No.Text + "%'";
What should i change in order to use '%' in my statement?
为了在我的陈述中使用'%',我应该改变什么?
2 个解决方案
#1
2
string sql = "SELECT * FROM Students WHERE convert(nvarchar,StudentNo) LIKE '%" + T_No.Text + "%'";
Note, however, that this is inefficient.
但请注意,这是低效的。
#2
1
Take a look at the following page.
请看下面的页面。
The % sign has a special meaning in SQL.
%符号在SQL中具有特殊含义。
#1
2
string sql = "SELECT * FROM Students WHERE convert(nvarchar,StudentNo) LIKE '%" + T_No.Text + "%'";
Note, however, that this is inefficient.
但请注意,这是低效的。
#2
1
Take a look at the following page.
请看下面的页面。
The % sign has a special meaning in SQL.
%符号在SQL中具有特殊含义。