views:

35

answers:

3

hi.. today i fot one error. i am not able to understand why it is. i hope somebody will help me here

my method is

  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;
            }
        }

when Da.Fill(Ds) is executed it throws error "Procedure or function 'GetUserFamilyInfo' expects parameter '@UserId', which was not supplied."

i have already added parameter @UserId. and i am getting its value also when debugging. still i am getting the error.

A: 

Is it definitely a BIGINT?

mcintyre321
+1  A: 

I don't know whether it's relevant, but you haven't specified the type of the command. If this is a stored procedure, try using:

Cmd.CommandType = CommandType.StoredProcedure;

It's possible that it's ignoring the parameter on the grounds that it doesn't appear anywhere in the text of the command - which doesn't make sense for a SQL query, but does make sense for a stored procedure.

If that doesn't help, you might want to look in the logs on SQL Server to see what it's actually being sent.

Jon Skeet
ya i got my mistake... i dint write this line Cmd.CommandType = CommandType.StoredProcedure;so it was providing error... thanks..
Radhi
+1  A: 

Maybe you need to set cmd.CommandType to StoredProcedure.

Konamiman