e.g.
Dim cmd As New ADODB.Command
Dim par As ADODB.Parameter
On Error GoTo fail
Set par = cmd.CreateParameter("", adVarChar, adParamInput, 0, "")
cmd.Parameters.Append par
Set par = cmd.CreateParameter("", adEmpty, adParamInput)
cmd.Parameters.Append par
cmd.CommandText = "EXEC MyProcedure ?,?"
cmd.Execute
GoTo noerror
fail:
MsgBox Err.Description, vbOK, "Error"
Err.Clear
noerror:
SQL Procedure:
create procedure MyProcedure
@Data as int,
@Data2 as varchar(10)
as
/* Do some processing */
NULL is not an empty string "" is an empty string and it is a value, but
NULL is not. To pass NULL using ADO parameter you need to assign it to the
parameter using next kind of code in VB
Set par = cmd.CreateParameter("", adVarChar, adParamInput, 0, NULL)
cmd.Parameters.Append par
But what is adEmpty parameter for? I do not think it is supported by SQL
Server stored procedures
--
Val Mazur
Microsoft MVP
"Johann Anhofer" <anh...@andromeda-software.at> wrote in message
news:eFNyIoe#CHA....@TK2MSFTNGP12.phx.gbl...
> NULL is not an empty string "" is an empty string and it is a value, but
> NULL is not. To pass NULL using ADO parameter you need to assign it to the
> parameter using next kind of code in VB
>
> Set par = cmd.CreateParameter("", adVarChar, adParamInput, 0, NULL)
> cmd.Parameters.Append par
>
Fine, but this is still not working, the same error occurs!
Btw. I know the difference between NULL and "", I wrote in my Posting about
to different problems.
1. How to pass an empty string as parameter ("")
2. How to pass a parameter having a NULL-Value
> But what is adEmpty parameter for? I do not think it is supported by SQL
> Server stored procedures
adEmpty is defined in the ADO DataTypeEnum, it's not part of the SQL-Server
Datatypes,
but I hoped, that it will replaced with NULL by ADO.
No, you should specify particular datatype, like adVarChar. Actually you
need to specify size of that parameter as well (I forgot to mention it in
previous posting). Next code should work fine, assuming that your parameter
was declared as VARCHAR(10) in your SP
Set par = cmd.CreateParameter("MyParam1", adVarChar, adParamInput, 10, Null)
cmd.Parameters.Append par
--
Val Mazur
Microsoft MVP
"Johann Anhofer" <anh...@andromeda-software.at> wrote in message
news:OOXS#Cf#CHA...@TK2MSFTNGP12.phx.gbl...
Francesco
"Johann Anhofer" <anh...@andromeda-software.at> a écrit dans le message de
news: eFNyIoe#CHA....@TK2MSFTNGP12.phx.gbl...
Yes ! Now it works. The point is the length of the parameter !
I must not be 0. The String may be NULL or "", but the length have to be
greater 0.
thanks, Johann