Monday, March 12, 2012

Passing a parameter into a stored procedure in a report ..........

Hi,

I have found this question asked many times online, but the answers always consisted of getting a parameter from the user and to the report. That is NOT what everyone was asking. I would like to know how to pass a parameter I already have into my stored procedure. Using Visual Studio 2005, in the "Data" tab of a report calling something like

Unique_Login_IPs

returns correctly when that stored proc takes no params, but when I have one that takes the year, for example, I do not know how to pass this info in.

Note: the following does not work in this context : EXEC Unique_Login_IPsParameterValue nor does EXEC Some_proc_without_params

Visual studio seems to want only the procedure name because it returns errors that say a procedure with the name "the entire line above like EXEC Unique_Login_IPsParameterValue" does not exist...

Thanks in advance,

Dustin L

Hi,

I am not very clear what you really need to do. What I understand is that you want to pass parameters to stored procedure right?

correct me if I am wrong, else you can do something like :

{

SqlConnection conn = new SqlConnection(DB.Config.Dsn);
conn.Open();
SqlCommand cmd = new SqlCommand("spCRMPublisherSummaryClear", conn);
cmd.CommandTimeout = 3600;
cmd.Parameters.AddWithValue("@.UserName", accountInfo.userName);
cmd.Parameters.AddWithValue("@.FirstName", accountInfo.firstName);
......so on for all your params
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();

}

Hope this helps.

Please dont forget to "Mark as Answer" if this post answers your question.

No comments:

Post a Comment