C# 使用C调用带参数的SQL Server存储过程

C# 使用C调用带参数的SQL Server存储过程,c#,sql-server,stored-procedures,C#,Sql Server,Stored Procedures,我正在尝试使用C代码调用一个非常简单的SQL Server存储过程。我有一个拥有authenticate方法的类。我正在将文本框值userID、password传递给这个方法,它不断地向我抛出关于未传递所需参数的错误。我基本上是一个从事C项目的商业智能专家。我们将不胜感激 以下是我正在执行的代码: sqcon.Open(); SqlCommand cmd = new SqlCommand("Users.PR_Authenticate_WebUsers",sqcon); cmd.Paramet

我正在尝试使用C代码调用一个非常简单的SQL Server存储过程。我有一个拥有authenticate方法的类。我正在将文本框值userID、password传递给这个方法,它不断地向我抛出关于未传递所需参数的错误。我基本上是一个从事C项目的商业智能专家。我们将不胜感激

以下是我正在执行的代码:

sqcon.Open();

SqlCommand cmd = new SqlCommand("Users.PR_Authenticate_WebUsers",sqcon);

cmd.Parameters.Add("@In_UserID", SqlDbType.VarChar).Value = "f";
cmd.Parameters.Add("@In_PassWord", SqlDbType.NVarChar).Value = "f";
cmd.Parameters.Add("@Out_IsAuthenticatedUser", SqlDbType.Bit);
cmd.Parameters["@Out_IsAuthenticatedUser"].Direction = ParameterDirection.Output;

cmd.ExecuteNonQuery();
sqcon.Close();

我不明白当我显式地传递参数值时,为什么它会抱怨没有传递值?我遗漏了什么吗?

Hmmm看起来您没有告诉命令对象它是一个存储过程而不是一个常规查询。试试这个

    sqcon.Open();
    SqlCommand cmd = new SqlCommand("Users.PR_Authenticate_WebUsers",sqcon);
    cmd.CommandType = CommandType.StoredProcedure;

    //Add parameters like this
    cmd.Parameters.Add(new SqlParameter("@In_UserID", "f"));
    sqcon.Close()

你有错误吗??给我们看完整的代码