Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的ExecuteOnQuery总是返回大于0的值_C#_Sql_Executenonquery - Fatal编程技术网

C# 为什么我的ExecuteOnQuery总是返回大于0的值

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

嗨,我现在正在为一个搜索框编码,该搜索框将从sql获取数据,并检查是否存在任何此类数据,但当我运行代码时

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