Forum Moderators: open

Message Too Old, No Replies

C# and stored procedure

Trouble with Parameters and Stored Procedures

         

MatthewSEaton

2:29 pm on Jul 14, 2003 (gmt 0)



All I am trying to do is to create a parameter and pass it to a stored procedure and return the results into a DataReader. I get an error when I execute the cmd.ExecuteReader() line. I'm pretty new to .net, but this code looks good to me.

The error is:

@portTypeID is not a parameter for procedure sp_FindPortfolioByType

Here is the code:

settingID = 1;
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

SqlCommand cmd = new SqlCommand("sp_FindPortfolioByType", conn);

cmd.CommandType = CommandType.StoredProcedure;

SqlParameter portTypeID = new SqlParameter("@portTypeID", System.Data.SqlDbType.Int, 4);

portTypeID.Value = settingID;

portTypeID.Direction = ParameterDirection.Input;

cmd.Parameters.Add(portTypeID);

conn.Open();

SqlDataReader dr = cmd.ExecuteReader();

Thanks

cshelby

3:40 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



Matthew,
It looks as though you might not have declared "@portTypeID" in your stored proc. You might want to check the spelling in both places (your code and your stored proc.)

HTH

Chris

webdevsf

3:46 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



Matthew,

Consider using the Microsoft Data Access Block for your data access routines. It is far simpler to use than writing directly against the SqlProvider. Source code is provided with the library, so you can modify it for your own needs.

[msdn.microsoft.com...]

WDSF