PRB: Parameterized RDO query results in Error 40002ID: Q183085
|
Some parameterized RDO queries result in Error 40002, "Invalid Parameter Number," if the SET NOCOUNT ON/OFF option is used within the SQL query text.
This problem can be resolved by not using a parameter query and instead
hard coding the parameters in the query string.
To do this, in the code below, comment out the lines of code beneath the
PROBLEM section. Then uncomment the line of code beneath the WORKAROUND
section.
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
DROP TABLE IdentTest
go
CREATE TABLE IdentTest
(
id INT IDENTITY,
Name CHAR(20) NULL
)
go
Private Sub Command1_Click()
Dim MyConnect As rdoConnection
Dim Rs As rdoResultset
Dim qy As rdoQuery
Dim szConnect As String
szConnect = "Driver={SQL Server}" & _
";Server=YOURSERVERNAME;uid=sa;pwd=;dsn='';Database=pubs"
Set MyConnect = rdoEnvironments(0).OpenConnection _
(dsname:="", prompt:=rdDriverNoPrompt, Connect:=szConnect)
Set qy = New rdoQuery
Set qy.ActiveConnection = MyConnect
'PROBLEM SECTION -- Having the (?) parameter in the below line
'results in Error 40002
'---------------------------------------------------------
qy.SQL = "SET NOCOUNT ON INSERT identtest(name)" _
& " VALUES( ? ) SELECT @@IDENTITY SET NOCOUNT OFF"
qy(0).Direction = rdParamInput '<<Error 40002 occurs on this line
qy(0) = "NewName"
'WORKAROUND SECTION
'----------------------------------------------------------
'qy.SQL = "SET NOCOUNT ON INSERT identtest(name)" _
& " VALUES('NewName') SELECT @@IDENTITY SET NOCOUNT OFF"
Set Rs = qy.OpenResultset
Debug.Print "The Identity is " & Rs(0).Value
Set qy = Nothing
Set Rs = Nothing
Set MyConnect = Nothing
End Sub
Additional query words: @@identity kbRDO kbVBp400 kbVBp500 kbVBp600 kbdse kbDSupport kbVBp
Keywords :
Version :
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: June 2, 1999