Wednesday, May 17, 2006

[itsdifferent] Return Parameters in OLEDB Connection

 

Hi

I am trying to open a connection using SQLOLEDB provider in .NET. I am returning a int value from Storeprocedure but i am getting following error.

I am writing .Net code and Store Procedure Code. Please replay if any body find any solution.

Thnaks

Mukesh Jain

Exception


System.Data.OleDb.OleDbException was unhandled
  Message="Procedure or function TEST has too many arguments specified."
  Source="Microsoft OLE DB Provider for SQL Server"
  ErrorCode=-2147217900
  StackTrace:
       at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
       at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
       at ConnTest.Form1.button2_Click (Object sender, EventArgs e) in C:\WFMS\Security\OLEDBConnection\ConnTest\Form1.cs:line 96
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ConnTest.Program.Main() in C:\WFMS\Security\OLEDBConnection\ConnTest\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context (Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

------------------------------

.Net Code

private void button2_Click(object sender, EventArgs e)

{

string sqlCommand = "TEST";

OleDbConnection con = new OleDbConnection ();

int returnValue;

OleDbCommand cmd = new OleDbCommand ();

string connectionString = "PROVIDER=SQLOLEDB;Data Source=Test;User ID=Test;password=Test;Initial Catalog=test" ;

con.ConnectionString = connectionString;

con.Open();

cmd.Connection = con;

cmd.CommandType =

CommandType.StoredProcedure;

cmd.CommandText = sqlCommand;

OleDbParameter sampParm1 = cmd.Parameters.Add("@count", OleDbType.Integer);

OleDbParameter sampParm2 = cmd.Parameters.Add("@count1", OleDbType.Integer);

OleDbParameter sampParm3 = cmd.Parameters.Add("RETURN_VALUE", OleDbType.Integer);

sampParm1.Direction =

ParameterDirection.Input;

sampParm2.Direction =

ParameterDirection.Input;

sampParm3.Direction =

ParameterDirection.ReturnValue;

cmd.Parameters[

"@count"].Value = 5;

cmd.Parameters[

"@count1"].Value = 120;

cmd.ExecuteNonQuery();

returnValue = (

int)sampParm3.Value;

con.Close();

}

 

Store Procedure

CREATE PROCEDURE [TEST]  ( @count AS INT ,@count1 AS INT ,@returnValue AS INT OUTPUT)

AS

BEGIN

Select @count,@count1

RETURN -1

 

END

 



Note: This Group is not a Job Searching Group, so please co-operate and dont transfer any kind of job related material across this Group.AnyOne doing so can be banned from the Group
Thanx , Group Co-Ordinators




YAHOO! GROUPS LINKS




No comments: