Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- From: MJ <MJ@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 6 Dec 2006 08:20:01 -0800
Hi,
I'm not sure if this is the right group to post this or not but I will
give it a try :(
I'm trying to convert an ASP application into ASP.NET 2.0 (changing the
extension for files .asp to .aspx and then fixing all the issues). While
fixing one of the page I found that the old page calls a stored procedure and
gets the data and this was done using ServerSide Java Script.
Now since this page has been changed to ASPX page 2.0 with the page
directive as <%@ Page Language="VB" %> I cannot use Server Side JavaScript
and VB Script on one page. So I decided to move the code to a class file. The
code looks something like this..
public static ADODB.Recordset GetDataAsADORecordSet_SP(string strSPName,
string strProductID, string strConn)
{
OleDbDataAdapter custDA = new OleDbDataAdapter();
ADODB.Connection adoConn = new ADODB.Connection();
ADODB.Recordset adoRS = new ADODB.Recordset();
ADODB.Command adoCommand = new ADODB.Command();
adoConn.Open(strConn, "", "", -1);
adoCommand.ActiveConnection = adoConn;
adoCommand.CommandType = CommandTypeEnum.adCmdStoredProc ;
adoCommand.CommandText = strSPName;
adoCommand.Parameters.Append(adoCommand.CreateParameter("product_id",
DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput,32 ,
Convert.ToInt32 (strProductID)));
object recordsAffected = 0;
object parameters;
parameters = new string[] {};
adoRS = adoCommand.Execute(out recordsAffected, ref parameters,
(int)ExecuteOptionEnum.adExecuteNoRecords );
int count = adoRS.RecordCount;
return adoRS;
}
Now when I call this function form the .aspx page it gives me an error on
line adoRS = adoCommand.Execute(out recordsAffected, ref parameters,
(int)ExecuteOptionEnum.adExecuteNoRecords ); the error that I get is
"[Microsoft][ODBC SQL Server Driver]Syntax error or access violation". Can
anyone point what’s wrong with this code and if there is another way to
execute the StoredProcedure.
I only want the data to come back as a RecordSet so that I've to change
minimum when I display the data on the page.
Any suggestions or pointer would be greatly appreciated.
Thanks in advance
MJ
.
- Follow-Ups:
- Re: Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- From: Erland Sommarskog
- Re: Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- Prev by Date: Re: Cursor Operation Conflict (no count and aduseclient fixes failed)
- Next by Date: Re: Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- Previous by thread: Cursor Operation Conflict (no count and aduseclient fixes failed)
- Next by thread: Re: Executing a StoredProcedure using ADOCommand object in ASP.NET 2.0
- Index(es):
Relevant Pages
|