2

I am trying to call a very simple SQL Server stored procedure using C# code. I have a class which has authenticate method. I am passing text box values (userID, password) to this method and it keeps on throwing me error about required parameter not being passed. I am basically a Business Intelligence professional working on C# project. Help will be appreciated.

Here is the code I am executing:

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();

I don't understand when I am passing parameter values explicitly why it complains about value not being passed? Am I missing something?

1
  • do u get some error ?? show us the full code Commented Sep 3, 2016 at 5:42

1 Answer 1

4

Hmmm looks like you are not telling the command object that it is a stored procedure not a regular query try this one

    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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.