Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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
.net 创建存储过程时出错_.net - Fatal编程技术网

.net 创建存储过程时出错

.net 创建存储过程时出错,.net,.net,显示错误。。当Sp_SelectCountry没有像dat这样的参数时,喜欢。。请帮帮我 看起来您试图用一条语句建立两个输入参数,这是不可能的。而是将语句分解为多个语句,每个参数对应一个语句,因此: int SpParam = 0; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandTyp

显示错误。。当Sp_SelectCountry没有像dat这样的参数时,喜欢。。请帮帮我

看起来您试图用一条语句建立两个输入参数,这是不可能的。而是将语句分解为多个语句,每个参数对应一个语句,因此:

            int SpParam = 0;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "sp_SelectCountry";
            cmd.Parameters.AddWithValue("@country_id,@country_name",SpParam);
            con.Open();
            cmd.ExecuteNonQuery();
            da = new SqlDataAdapter(cmd);
            da.Fill(dtCountry);
            con.Close();

其中,countryId和countryName是正确类型的局部变量,初始化为您希望在调用存储过程时使用的值。

欢迎使用堆栈溢出!您可能需要阅读以下内容:和此:它仍然显示相同的错误。。程序sp_SelectCountry没有参数,并且提供了参数。cmd.Parameters.AddWithValue(“@country\u id”,SpParam);cmd.Parameters.AddWithValue(“@country_name”,SpParam);在这种情况下,将参数添加到用于执行查询的
命令
对象的
参数
集合是错误的。您是否有能力查看存储过程的源代码,或者有关存储过程的文档?如果不知道存储过程所期望的输入和/或输出参数,那么执行它就很困难。
...
cmd.Parameters.AddWithValue("@country_id", countryId);
cmd.Parameters.AddWithValue("@country_name", contryName);
...