Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# ADO Executing Stored Procedure Problem
Message
From
18/01/2009 11:11:13
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01374697
Message ID:
01374776
Views:
9
Hi Kevin,

You've left out the name of the parameter, which I assume you want to be the same as the column name. You need to add something like this to your ExecuteStoredProc class:
oParam.ParameterName = "@" +  oColParam.sSrcColName;
~~Bonnie


>I posted something similar a while back, and I still cant get this to work.
>
>I wrote a data access class. It has an ExecuteStoredProc method which accepts a class that contains all the necessaru info, such as the name of the sproc and a collection of params to pass to SQL.
>
>I'm getting the exception "@Parameter1 is not a parameter for procedure bm_GetAppOverview."
>
>I run it like this. As you can see, I specified the parameter column name as "AppKey". Anyone know what's happening?
>
>
>static void Main(string[] args)
>{
>    DataAccess oDataAccess = new DataAccess();
>
>    oDataAccess.Provider = DataAccess.ProviderType.SQL;
>    oDataAccess.ConnectionString = sConnString;
>
>
>    // Paramaters collection object
>    DataAccess.ProcedureParams oParams = new DataAccess.ProcedureParams();
>    oParams.sProcedureName = "bm_GetAppOverview";
>
>    // Create param objects and add to the collection
>    DataAccess.Param oAppKey = new DataAccess.Param();
>    oAppKey.Direction = System.Data.ParameterDirection.Input;
>    oAppKey.iSize = 0;
>    oAppKey.sSrcColName = "AppKey";
>    oAppKey.value = 0;
>
>    oParams.AddParam(oAppKey);
>
>    // Call into the data access class & run the sproc
>    DataSet oData = oDataAccess.ExecuteStoredProc(oParams);
>}
>
>
>Here's the ExecuteStoredProc code:
>
>
>public DataSet ExecuteStoredProc(ProcedureParams oParams)
>{
>    DataSet oDataSet = new DataSet();;
>
>    IDbCommand oCommand = _GetCommand(oParams.sProcedureName);
>
>    if (oCommand != null)
>    {
>        oCommand.CommandType = CommandType.StoredProcedure;
>
>        foreach (Param oColParam in oParams.Params)
>        {
>            SqlParameter oParam = new SqlParameter();
>
>            oParam.DbType = oColParam.Type;
>            oParam.Direction = oColParam.Direction;
>            oParam.SourceColumn = oColParam.sSrcColName;
>            oParam.Size = oColParam.iSize;
>            oParam.Value = oColParam.value;
>
>            oCommand.Parameters.Add(oParam);
>        }
>
>        IDbDataAdapter oAdapter = _GetDataAdapter(oParams.sProcedureName);
>
>        if (oAdapter != null)
>        {
>
>            oAdapter.SelectCommand = oCommand;
>
>            try
>            {
>                oAdapter.Fill(oDataSet);
>
>            }
>            catch (SqlException e)
>            {
>                // Removed for brevity
>            }
>        }
>    }
>    return oDataSet;
>
>
>
>I know the _GetCommand and _GetDataAdapter methods work because they are already in use elsewhere.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform