vb code help

roh_8_it_3

Registered User.
Local time
Today, 13:47
Joined
Feb 15, 2005
Messages
79
Hi,

I am calling a stored procedure..through vb.SP expects 2 parameters.

but i m getting error "operation cannot be performed when the object is closed".This is the code

Dim db1 As ADODB.Connection
Dim cmd1 As ADODB.Command
Dim prm1 As ADODB.Parameter
Dim prm2 As ADODB.Parameter
Dim rs1 As ADODB.Recordset

Set cmd1 = New Command
Set rs1 = New ADODB.Recordset
Set db1 = rtnConnection

Set cmd1.ActiveConnection = db1
cmd1.CommandType = adCmdStoredProc
cmd1.CommandText = "spname"

Set prm1 = cmd1.CreateParameter("param1", adChar, adParamInput, 3, BMF)
Set prm2 = cmd1.CreateParameter("param2", adInteger, adParamInput, 4, chnnlstobook)


cmd1.Parameters.Append prm1
cmd1.Parameters.Append prm2

Set rs1 = cmd1.Execute

If Not rs1.EOF Then
txtfield= rs1(1)
End If

On rs1.eof it gives me that message

Pls any help on this i am trying a lot to find the solution for this.
 
Where is rtnConnection defined?
 
rtnconnection is the connection string.Its defined in the global Module of my Project.

The problem is in passing the parameters to the stored procedure.I checked this.If the SP is expecting params in varchar and from the code if i supplies the params like this-


Set prm1 = cmd1.CreateParameter("param1", adChar, adParamInput, 3, val1)
Set prm2 = cmd1.CreateParameter("param2", adChar, adParamInput, 3, val2)

Thsn it works fine and my recordset is bein populated.

But my SP expects param1 in varchar and param2 as numeric(9,4).I am making mistake in passing this parameters.I am trying like this-

Set prm1 = cmd1.CreateParameter("param1", adChar, adParamInput, 25, val1)
Set prm2 = cmd1.CreateParameter("param2", adnumeric, adParamInput, 9, val2)


It says invalid precision.In the vode code ,i have defined val2 as double.

Could any tell me how to pass the params to the SP from the vb code particulary taking this as example.

Thanks
 

Users who are viewing this thread

Back
Top Bottom