Board index » delphi » Command objects, forward-only cursors, and EmptyParam
roger.mor...@nospamdial.pipex.com (Roger Morton)
![]() Delphi Developer |
Mon, 09 Sep 2002 03:00:00 GMT
Command objects, forward-only cursors, and EmptyParam
At the end of this post is a very useful piece of advice from Alejandro Mesa, posted a couple of weeks ago in microsoft.public.data.ado. It explains how to obtain a recordset from a parameterised query, using the command object in a way that works around the normal limitation of a firehose cursor.
The only problem for me is that it's in VB, and I'm getting really frustrated trying to get Delphi to do the same thing. The specific piece of code that I have trouble with is ostensibly very simple: rs.Open cmd, , adOpenStatic, adLockBatchOptimistic The second argument is missing - the MS help says quite specifically that you must not attempt to define a connection at this point, if you're using a commnad object as your source. The fifth argument is also missing - MS 'imply' that the Options argument is not used when a command object is supplied. Now - I can replicate this in Delphi (exactly as above, plus a couple of enclosing parentheses) with late binding. But the following fails, with late binding: rs.Open( cmd, EmptyParam, adOpenStatic, adLockBatchOptimistic) It returns with the inconsistent / incompatible / missing arguments error message. Why does it fail? Isn't EmptyParam advertised as being equivalent to an optional parameter not being supplied? And what I really want to do is get it work with *early* binding, which is where EmptyParam would appear to be mandatory. rs.Open( cmd, ?????, adOpenStatic, adLockBatchOptimistic, adCmdStoredProc) 'cos EmptyParam doesn't work :-) Any ideas / thoughts? Roger Morton ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Create the command, add parameters, assign value to the parameters and use the command object as recordset source. Example: Private Sub Command1_Click() On Error GoTo ErrorHandler Set cn = New ADODB.Connection cn.Provider = "sqloledb" cmd.ActiveConnection = cn rs.CursorLocation = adUseClient ExitSub: Exit Sub ErrorHandler: Resume ExitSub |