Groups | Blog | Home
all groups > sql server programming > august 2004 >

sql server programming : Parameters


Hugo Kornelis
8/24/2004 1:48:53 PM
[quoted text, click to view]
(much snippage)

[quoted text, click to view]

Hi Angelo,

In the code preceding the error, you declare and use an ADODB.Parameter
object with the name objparam1; here you suddenly start using objParm
(without the second letter "a").

Best, Hugo
--

Angelo Campitelli
8/24/2004 9:46:26 PM

Hi,

Im trying to insert some data into a sql server db (well msde) using
vbscript however i cant seem to get parameters to work. I get a type mismach
trying to add a parameter. The DB fields are both varchar size:2048. Any
ideas? See the error message on the bottom of the post.

Angelo Campitelli


' ADODB CONSTANTS
' Cursor Types
Const adOpenForwardOnly = 0
Const adOpenDynamic = 2
Const adCmdText = 1
Const adOpenStatic = 3

' Lock Types
Const adLockReadOnly = 1
Const adLockPessimistic = 2
Const adLockOptimistic = 3

'SQL SERVER type CONSTANTS
Const adArray = 0 ' x2000 Combine with another data type
to indicate that
the other data type is an array
Const adBigInt = 20 ' 8-byte signed integer
Const adBinary = 128 ' Binary
Const adBoolean = 11 ' True or false Boolean
Const adBSTR = 8 ' Null-terminated character string
Const adChapter = 136 ' 4-byte chapter value for a child
recordset
Const adChar = 129 ' String
Const adCurrency = 6 ' Currency format
Const adDate = 7 ' Number of day since 12/30/1899
Const adDBDate = 133 ' YYYYMMDD date format
Const adDBFileTime = 137 ' Database file time
Const adDBTime = 134 ' HHMMSS time format
Const adDBTimeStamp = 135 ' YYYYMMDDHHMMSS date/time format
Const adDecimal = 14 ' Number with fixed precision and
scale
Const adDouble = 5 ' Double precision floating-point
Const adEmpty = 0 ' no value
Const adError = 10 ' 32-bit error code
Const adFileTime = 64 ' Number of 100-nanosecond
intervals since 1/1/1601

Const adGUID = 72 ' Globally unique identifier
Const adIDispatch = 9 ' Currently not supported by ADO
Const adInteger = 3 ' 4-byte signed integer
Const adIUnknown = 13 ' Currently not supported by ADO
Const adLongVarBinary = 205 ' Long binary value
Const adLongVarChar = 201 ' Long string value
Const adLongVarWChar = 203 ' Long Null-terminates string
value
Const adNumeric = 131 ' Number with fixed precision and
scale
Const adPropVariant = 138 ' PROPVARIANT automation
Const adSingle = 4 ' Single-precision floating-point
value
Const adSmallInt = 2 ' 2-byte signed integer
Const adTinyInt = 16 ' 1-byte signed integer
Const adUnsignedBigInt = 21 ' 8-byte unsigned integer
Const adUnsignedInt = 19 ' 4-byte unsigned integer
Const adUnsignedSmallInt = 18 ' 2-byte unsigned integer
Const adUnsignedTinyInt = 17 ' 1-byte unsigned integer
Const adUserDefined = 132 ' User-defined variable
Const adVarBinary = 204 ' Binary value
Const adVarChar = 200 ' String
Const adVariant = 12 ' Automation variant
Const adVarNumeric = 139 ' Variable width exact numeric with
signed scale
Const adVarWChar = 202 ' Null-terminated Unicode
character string
Const adWChar = 130 ' Null-terminated Unicode character
string

'SQL SERVER PARAMETER CONSTANTS
Const adParamInput = 1 ' Input parameter
Const adParamInputOutput = 3 ' Both input and output
parameter
Const adParamOutput = 2 ' Output parameter
Const adParamReturnValue = 4 ' Return value
Const adParamUnknown = 0 ' Direction is unknown

'SQL SERVER PROCEDRE TYPE CONSTANTS
Const adCmdUnspecified = -1 ' Does not specify the command
type argument.
'Const adCmdText = 1 ' Evaluates CommandText as a textual
definition of a
command or stored procedure call.
Const adCmdTable = 2 ' Evaluates CommandText as a table
name whose columns
are all returned by an internally generated SQL query.
Const adCmdStoredProc = 4 ' Evaluates CommandText as a stored
procedure
name.
Const adCmdUnknown = 8 ' Default. Indicates that the
type of command in
the CommandText property is not known.
Const adCmdFile = 256 ' Evaluates CommandText as the
file name of a
persistently stored Recordset. Used with Recordset.Open or Requery only.
Const adCmdTableDirect = 512 ' Evaluates CommandText as a
table name whose
columns are all returned. Used with Recordset.Open or Requery only. To use
the
Seek method, the Recordset must be opened with adCmdTableDirect.
' This value cannot be combined with the
ExecuteOptionEnum value
adAsyncExecute.





Dim cnn
Dim rst
Dim strSQL

Dim objCon
Dim objCmd
Dim objparam1
Dim objparam2

Set objparam1 = CreateObject("ADODB.Parameter")
Set objparam2 = CreateObject("ADODB.Parameter")

Set objCon = CreateObject("ADODB.Connection")
Set objCmd = CreateObject("ADODB.Command")


strSQL = "SELECT * from printers where
distinguishedName=@strdistinguishedName and uncname=@strUncName"
cnn = "Provider=sqloledb;Data Source=TESTSERVER;Initial
Catalog=LOGIN;Integrated Security=SSPI"

objCon.Open cnn


objCmd.Commandtext = strSQL
objCmd.CommandType = adCmdText


objparam1.name = "strdistinguishedName"
objparam1.type = adVarChar
objparam1.direction = adParamInput
objparam1.value = strdistinguishedName

objparam2.name = "strUncName"
objparam2.type = adVarChar
objparam2.direction = adParamInput
objparam2.value = strUncName

objCmd.Parameters.Append objParm1 <<<<<---- ERROR HERE (see below)
objCmd.Parameters.Append objParm2

---------- ERROR ----------
Type Mismatch
80020005
Source : Provider

Angelo Campitelli
8/24/2004 10:14:28 PM
Dear Hugo,

Oh dear... That was it thanks very much. I tried just about everything.
Looks like my typing is worse than my coding !. It's a case of you need
another pair of eyes to look at it !.

Angelo Campitelli

[quoted text, click to view]

AddThis Social Bookmark Button