michael801
asked on
How to include stored procedure input parameters when using ado data control; VB 6.0, SQL Server 2000
I have been unable to find instructions regarding this question in help files, at microsoft, or via google.
I am using VB 6.0 sp6 w/ WinXP Pro sp2, and SQL Server 2000.
I am trying to use an ado data control to fill a dbgrid.
I am trying to call a stored procedure with 2 input parameters.
I need to know how to include the parameters in the subprocedure that calls the stored procedure.
The error I receive is, "Adodc1 - Procedure'WHTSP_FetechRepo rderDetail s' expects parameter '@emp_id' which was not supplied."
I know this isn't correct - can someone provide an example? My thanks in advance for any helpful responses.
Here is the code for the subprocedure:
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail s"
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id" , adVarChar, adParamInput, 5, strEMP_ID)
.Parameters.Append .CreateParameter("@date_sc anned", adsmalldatetime, adParamInput, , dtmTodaysDate)
End With
With Adodc1
.ConnectionString = CommonConnString
.CursorLocation = adUseServer
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.CommandType = adCmdStoredProc
.RecordSource = WHTSP_FetchReporderDetails
.Refresh
End With
I am using VB 6.0 sp6 w/ WinXP Pro sp2, and SQL Server 2000.
I am trying to use an ado data control to fill a dbgrid.
I am trying to call a stored procedure with 2 input parameters.
I need to know how to include the parameters in the subprocedure that calls the stored procedure.
The error I receive is, "Adodc1 - Procedure'WHTSP_FetechRepo
I know this isn't correct - can someone provide an example? My thanks in advance for any helpful responses.
Here is the code for the subprocedure:
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id"
.Parameters.Append .CreateParameter("@date_sc
End With
With Adodc1
.ConnectionString = CommonConnString
.CursorLocation = adUseServer
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.CommandType = adCmdStoredProc
.RecordSource = WHTSP_FetchReporderDetails
.Refresh
End With
Best advice would be lose the Data Control and bind the data grid directly to a resultset that supports bookmarks.
ASKER
Hi angelIII:, thanks for the FAST response - I tried your suggestion, but I received a compile eror: 'Type mismatch'. Here is the code with the suggested change:
Dim conn As New ADODB.Connection
conn.Open CommonConnString
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail s"
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id" , adVarChar, adParamInput, 5, strEMP_ID)
.Parameters.Append .CreateParameter("@date_sc anned", adDBTime, adParamInput, , dtmTodaysDate)
End With
With Adodc1
.ConnectionString = CommonConnString
.CursorLocation = adUseServer
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.CommandType = adCmdStoredProc
.RecordSource = cmd '<-- Compile error Type Mismatch
.Refresh
End With
Dim conn As New ADODB.Connection
conn.Open CommonConnString
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id"
.Parameters.Append .CreateParameter("@date_sc
End With
With Adodc1
.ConnectionString = CommonConnString
.CursorLocation = adUseServer
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.CommandType = adCmdStoredProc
.RecordSource = cmd '<-- Compile error Type Mismatch
.Refresh
End With
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>angelIII:I see I submit before finishing to write...
.RecordSource = cmd.Execute<
Thanks.
The compile error still occurs, highlighting 'RecordSource = '
It may be that what I'm asking cannot be done; or in any event will take more time than coding without the control.
I agree with both angellll and acperkins, my attempt to shortcut by retaining the ado dc is most likely ill-advised. I accept both solutions, I weight the percentage split in favor of angellll for the extra effort. My thanks to both.
.RecordSource = cmd.Execute<
Thanks.
The compile error still occurs, highlighting 'RecordSource = '
It may be that what I'm asking cannot be done; or in any event will take more time than coding without the control.
I agree with both angellll and acperkins, my attempt to shortcut by retaining the ado dc is most likely ill-advised. I accept both solutions, I weight the percentage split in favor of angellll for the extra effort. My thanks to both.
>>It may be that what I'm asking cannot be done<<
Sure it can.
You cannot do this (as you have discovered, they are different animals):
.RecordSource = cmd
And you cannot bind to a recordset that does not support bookmarks. When you use the Command's Execute method you create a firehose (forward-only, read-only) cursor. This resultset cannot be used to bind to a grid. So as I stated previously the workaround is to use the Recordset's Open method to create the appropriate resultset. As in (plagiarizing AngelIII's code):
Dim conn As ADODB.Connection, cmd As ADODB.Command, rs as ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open CommonConnString
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail s"
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id" , adVarChar, adParamInput, 5, strEMP_ID)
.Parameters.Append .CreateParameter("@date_sc anned", adDBTime, adParamInput, , dtmTodaysDate)
Set rs = New ADODB.Recordset
With rs
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open Cmd
End With
End With
Set Cmd = Nothing
Rest of your code goes here. If you insist on using the ADO Data Control than the rest of the code would look something like this:
Set Adodc1.Recordset = rs
Adodc1.Refresh
Sure it can.
You cannot do this (as you have discovered, they are different animals):
.RecordSource = cmd
And you cannot bind to a recordset that does not support bookmarks. When you use the Command's Execute method you create a firehose (forward-only, read-only) cursor. This resultset cannot be used to bind to a grid. So as I stated previously the workaround is to use the Recordset's Open method to create the appropriate resultset. As in (plagiarizing AngelIII's code):
Dim conn As ADODB.Connection, cmd As ADODB.Command, rs as ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open CommonConnString
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id"
.Parameters.Append .CreateParameter("@date_sc
Set rs = New ADODB.Recordset
With rs
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open Cmd
End With
End With
Set Cmd = Nothing
Rest of your code goes here. If you insist on using the ADO Data Control than the rest of the code would look something like this:
Set Adodc1.Recordset = rs
Adodc1.Refresh
ASKER
Thank you very much - I had to put the first end with back where it came from and things seem to work ok. I'm posting this for anyone in the future that may be interested. Kind regards, m801.
Dim conn As ADODB.Connection, cmd As ADODB.Command, rs as ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open CommonConnString
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail s"
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id" , adVarChar, adParamInput, 5, strEMP_ID)
.Parameters.Append .CreateParameter("@date_sc anned", adDBTime, adParamInput, , dtmTodaysDate)
End With
Set rs = New ADODB.Recordset
With rs
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open Cmd
End With
Set Cmd = Nothing
Rest of your code goes here. If you insist on using the ADO Data Control than the rest of the code would look something like this:
Set Adodc1.Recordset = rs
Adodc1.Refresh
Dim conn As ADODB.Connection, cmd As ADODB.Command, rs as ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open CommonConnString
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id"
.Parameters.Append .CreateParameter("@date_sc
End With
Set rs = New ADODB.Recordset
With rs
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open Cmd
End With
Set Cmd = Nothing
Rest of your code goes here. If you insist on using the ADO Data Control than the rest of the code would look something like this:
Set Adodc1.Recordset = rs
Adodc1.Refresh
.RecordSource = cmd
Dim cmd As New ADODB.Command
With cmd
.CommandType = adCmdStoredProc
.CommandText = "WHTSP_FetchReporderDetail
.ActiveConnection = conn
.Parameters.Append .CreateParameter("@emp_id"
.Parameters.Append .CreateParameter("@date_sc
End With
With Adodc1
.ConnectionString = CommonConnString
.CursorLocation = adUseServer
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.CommandType = adCmdStoredProc
.RecordSource = cmd
.Refresh
End With