C# 为什么我的ExecuteOnQuery总是返回大于0的值
嗨,我现在正在为一个搜索框编码,该搜索框将从sql获取数据,并检查是否存在任何此类数据,但当我运行代码时C# 为什么我的ExecuteOnQuery总是返回大于0的值,c#,sql,executenonquery,C#,Sql,Executenonquery,嗨,我现在正在为一个搜索框编码,该搜索框将从sql获取数据,并检查是否存在任何此类数据,但当我运行代码时 public void checkValues() { using (connection = new SqlConnection(connectionString)) using (SqlCommand cmdMovname = new SqlCommand("select Film_name from product where Film_name
public void checkValues()
{
using (connection = new SqlConnection(connectionString))
using (SqlCommand cmdMovname = new SqlCommand("select Film_name from product where Film_name like'%the value here is not in the sql data %'", connection))
{
connection.Open();
if (cmdMovname.ExecuteNonQuery() != 0)
{
SetValues();
find = "Search result for \"the value here is not in the sql data\"";
}
else if (cmdMovname.ExecuteNonQuery() == 0)
{
find = "Sorry , no search result for \"the value here is not in the sql data\"";
}
}
}
find的字符串值将始终为“Search result for\”此处的值不在sql数据中
有人能帮我解决这个问题吗?因为我还不熟悉使用sql数据库请尝试改用ExecuteReader。您正在尝试执行查询,但使用ExecuteOnQuery函数,在这种情况下该函数将返回-1
.因为select语句的
ExecuteOnQuery
的返回值始终为-1:。为什么要在中执行查询,否则如果?谢谢,我不知道默认情况下ExecuteOnQuery将返回-1