Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.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/80.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# 参数未通过_C#_Sql_Sql Server 2008 - Fatal编程技术网

C# 参数未通过

C# 参数未通过,c#,sql,sql-server-2008,C#,Sql,Sql Server 2008,今天我犯了一个错误。我不明白为什么会这样。我希望有人能在这里帮助我 我的方法是 public UserFamilyInfoBO GetUserFamilyInfo(Int64 UserId) { try { DataSet Ds = new DataSet(); SqlCommand Cmd = new SqlCommand("GetUserFamilyInfo",

今天我犯了一个错误。我不明白为什么会这样。我希望有人能在这里帮助我

我的方法是

  public UserFamilyInfoBO GetUserFamilyInfo(Int64 UserId)
        {
            try
            {
                DataSet Ds = new DataSet();
                SqlCommand Cmd = new SqlCommand("GetUserFamilyInfo", Cn);
                SqlDataAdapter Da = new SqlDataAdapter();
                Da.SelectCommand = Cmd;
                Cmd.Parameters.Add("@UserId", SqlDbType.BigInt).Value = UserId;

                Cn.Open();
                Da.Fill(Ds);
                Cn.Close();
                return SetBO(Ds.Tables[0]);
            }
            catch (Exception)
            {
                return null;
            }
        }
当执行Da.Fill(Ds)时,它抛出错误 过程或函数“GetUserFamilyInfo”需要未提供的参数“@UserId”


我已经添加了参数@UserId。我在调试时也得到了它的值。我仍然得到了错误。

我不知道它是否相关,但您尚未指定命令的类型。如果这是存储过程,请尝试使用:

Cmd.CommandType = CommandType.StoredProcedure;
它可能会忽略该参数,因为它没有出现在命令文本中的任何地方——这对SQL查询没有意义,但对存储过程有意义


如果没有帮助,您可能需要查看SQL Server上的日志,以查看它实际发送的内容。

可能需要设置为
StoredProcedure

在将cmd分配给数据适配器之前是否尝试添加参数?只是想一想我弄错了。。。我只能写这行Cmd.CommandType=CommandType.StoredProcess;所以它提供了错误。。。谢谢