VB6->SQL 7 Stored Procedure with Parameters 
Author Message
 VB6->SQL 7 Stored Procedure with Parameters

I am getting the following error is IIS5 "Procedure 'FindCustomer' expects

I have the following stored procedure in SQL Server 7:

AS
SELECT CustomerNumber,Firstname,Surname
FROM Customer



I want to return a RecordSet using the following code VB6 SP4:
I have set up references to the ASP Object library and ADO 2.5

Public Sub FindCustomers()
On Error GoTo ErrorCode
Dim DBConn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim RS As New ADODB.Recordset
Dim prt As New ADODB.Parameter

Dim connStr As String
connStr = "PROVIDER=SQLOLEDB;DRIVER={SQL
Server};SERVER=DAVIDM;DATABASE=CallCentre;UID=callstaff;PWD=lauren;"

PostCode = CStr(ASPrequest.QueryString("PostCode"))
HouseNumber = CStr(ASPrequest.QueryString("HouseNumber"))
Surname = CStr(ASPrequest.QueryString("Surname"))

DBConn.ConnectionString = connStr
DBConn.Open

Set cmd.ActiveConnection = DBConn
cmd.CommandText = "FindCustomer"
cmd.CommandType = adCmdStoredProc
cmd.CommandTimeout = 15

Set prt = cmd.CreateParameter("post", adVarChar, adParamInput, 8)
cmd.Parameters.Append prt
Set prt = cmd.CreateParameter("surn", adVarChar, adParamInput, 15)
cmd.Parameters.Append prt
Set prt = cmd.CreateParameter("house", adVarChar, adParamInput, 6)
cmd.Parameters.Append prt

Set RS = cmd.Execute

If RS.BOF = True And RS.EOF = True Then
    Response.Write "CUSTOMER NOT FOUND"
Else
    Response.Write RS.Fields("CustomerNumber").Value
    Response.Write "<br>"
End If

RS.Close
Set RS = Nothing
DBConn.Close
Set DBConn = Nothing

Exit Sub

ErrorCode:
Response.Write Err.Description
If RS.State = adStateOpen Then
    RS.Close
    Set RS = Nothing
End If

If DBConn.State = adStateOpen Then
    DBConn.Close
    Set DBConn = Nothing
End If

End Sub

Any help greatly appreciated,

David Moffat
Glasgow
UK



Wed, 09 Apr 2003 03:00:00 GMT  
 VB6->SQL 7 Stored Procedure with Parameters
I'm a little new to this all but I have been executing stored procedures
directly and supplying the parameters in the sql string: I have set up a
connection I call gConn.

sql = "exec FindCustomer '" & Value1 & "','" & Date1 & "' " etc.
rs.ActiveConnection = gConn
rs.open  sql
rs.ActiveConnection = Nothing

I leave gConn open for the duration of my session but, of course, it could
be opened and closed at will.

Actually, I don't see where you are assigning any values to your parameters
after you create and append them. But I'm not very familiar with them so I
might be missing something simple.

Doug


Quote:
> I am getting the following error is IIS5 "Procedure 'FindCustomer' expects

> I have the following stored procedure in SQL Server 7:
> CREATE procedure FindCustomer



> AS
> SELECT CustomerNumber,Firstname,Surname
> FROM Customer



> I want to return a RecordSet using the following code VB6 SP4:
> I have set up references to the ASP Object library and ADO 2.5

> Public Sub FindCustomers()
> On Error GoTo ErrorCode
> Dim DBConn As New ADODB.Connection
> Dim cmd As New ADODB.Command
> Dim RS As New ADODB.Recordset
> Dim prt As New ADODB.Parameter

> Dim connStr As String
> connStr = "PROVIDER=SQLOLEDB;DRIVER={SQL
> Server};SERVER=DAVIDM;DATABASE=CallCentre;UID=callstaff;PWD=lauren;"

> PostCode = CStr(ASPrequest.QueryString("PostCode"))
> HouseNumber = CStr(ASPrequest.QueryString("HouseNumber"))
> Surname = CStr(ASPrequest.QueryString("Surname"))

> DBConn.ConnectionString = connStr
> DBConn.Open

> Set cmd.ActiveConnection = DBConn
> cmd.CommandText = "FindCustomer"
> cmd.CommandType = adCmdStoredProc
> cmd.CommandTimeout = 15

> Set prt = cmd.CreateParameter("post", adVarChar, adParamInput, 8)
> cmd.Parameters.Append prt
> Set prt = cmd.CreateParameter("surn", adVarChar, adParamInput, 15)
> cmd.Parameters.Append prt
> Set prt = cmd.CreateParameter("house", adVarChar, adParamInput, 6)
> cmd.Parameters.Append prt

> Set RS = cmd.Execute

> If RS.BOF = True And RS.EOF = True Then
>     Response.Write "CUSTOMER NOT FOUND"
> Else
>     Response.Write RS.Fields("CustomerNumber").Value
>     Response.Write "<br>"
> End If

> RS.Close
> Set RS = Nothing
> DBConn.Close
> Set DBConn = Nothing

> Exit Sub

> ErrorCode:
> Response.Write Err.Description
> If RS.State = adStateOpen Then
>     RS.Close
>     Set RS = Nothing
> End If

> If DBConn.State = adStateOpen Then
>     DBConn.Close
>     Set DBConn = Nothing
> End If

> End Sub

> Any help greatly appreciated,

> David Moffat
> Glasgow
> UK



Wed, 09 Apr 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Seeking advice on VB6->ADO->SQL Stored Procedure Error Handling

2. Seeking advice on VB6->ADO->SQL Stored Procedure Error Handling

3. SQL Stored Procedures Using Parameters in CR8.5/VB6

4. ado recordsets from stored procedures, stored procedures have input parameters

5. CR7 (ocx)+ VB6 + Stored Procedure parameters

6. Can't set date-time type stored procedure parameters in VB6

7. Passing Stored Procedure parameters via VB6 into Crystal Report (ver 8)

8. How to pass null parameters to a stored procedure VB6/Oracle 8

9. How to pass null parameters to a stored procedure VB6/Oracle 8

10. Executing to SQL Stored Procedure with parameters

11. VB.NET,SQL SERVER 2000 STORED PROCEDURE PARAMETERS, CRYSTAL REPORTS

12. Passing parameters from Excel to SQL 6.5 stored procedures

 

 
Powered by phpBB® Forum Software