Friday, February 10, 2012

Calling Stored Procedures using plain ADO in C#

Hello All,

We are trying to figure out how to make a stored procedure call and pass some inputs using C# and plain ADO. We are able to call an empty stored procedure but cannot pass parameters into a stored procedure.

Does anyone have sample code in C# whereby we can open a connection and pass inputs into a stored procedure? The following is a sample code we are using:

ADODB.Parameter param = new ADODB.Parameter();

param=cmd.CreateParameter("@.StoreID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput,sizeof(int) , 9);

cmd.Parameters.Append(param);

ADODB.Recordset rsInv = cmd.Execute(out objAffected, ref objAffected,-1 );

In the above example, we create a parameter of type integer and try to add it to the ADO Command object. It is supposed to return a recordset. It returns a recordset with record count -1.

Sincerely,

Dwight Kulkarni


Did you check the EOF property for the Recordset? The RecordCount property is not always an accurate indicator of how many rows have been returned, and in some instances will return a value of -1 (such as for a forward-only cursor).|||

It was a simple thing of course, the cursor location was EOF.

Thanks.

No comments:

Post a Comment