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 "Proce开发者_运维技巧dure 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.
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.
Maybe you need to set cmd.CommandType to StoredProcedure
.
精彩评论