Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing null value in stored procedure call

Status
Not open for further replies.

graabein

Programmer
Oct 9, 2002
186
NO
Hello, I've read the FAQ but couldn't see the answer there. Not much luck googling either.

The question is simple. How do I pass a NULL value to a stored procedure that's expecting a datetime value?

Code:
cmd.ActiveConnection = myConnection
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "usp_StoredProc"

cmd.Parameters.Append cmd.CreateParameter("@Number", adInteger, , , nIntValue)
cmd.Parameters.Append cmd.CreateParameter("@Date", adDate, ...



[elephant2]
graabein
 
I have another problem now.

When I execute the stored procedure command I want the returned rows in a recordset and also I want to check some output parameters.

But the output parameters seem to be empty.

Here is my code:
Code:
...
cmd.Parameters.Append cmd.CreateParameter("@Output", adTinyInt, adParamOutput)
Set rs = cmd.Execute
Debug.Print "@Output = " & cmd.Parameters("@Output").Value

And my stored procedure have the following code snippets:
Code:
CREATE PROCEDURE dbo.usp_StoredProc(
  @Number int,
  @Date datetime,
  @Output tinyint output) 
AS 
set @Output = 0
select * from SomeTempTable
GO

I can't see what I am doing wrong?

[elephant2]
graabein
 
Yet again I find the solution after I've posted the question... According to I have to close the recordset before I get access to the output parameters.

So if I do like this:
Code:
Set rsTemp = cmd.Execute
Set rs = rsTemp 'I want to process rs later
rsTemp.Close
Set rsTemp = Nothing
Debug.Print "@Output = " & cmd.Parameters("@Output").Value

I actually get a value in the output parameter!

[elephant2]
graabein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top