Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display sql data to flexgrid via stored procedure

Status
Not open for further replies.

Stripes1283

Programmer
Jun 13, 2007
28
0
0
ZA
Hi there I am struggling with this stored procedure in vb6. I have written all the code but it gives me a subscript out of range error. I have attached the code in the app and then the sp afterwards. What I am trying to do is to select data from tblTargetSpendPerHead from sql via a stored procedure, and then display it in a flexgrid. I would appreciate any help.


Code:

Private Sub cmdList_Click()
On Error GoTo ErrHand

Set conSQL = New ADODB.Connection
Set Cmd = New ADODB.Command

conSQL.Open sDBsrc

Cmd.ActiveConnection = conSQL
Cmd.CommandText = "dbo.prcTargetLoad"
Cmd.CommandType = adCmdStoredProc

' First Parameter
With oParam(0)
.Name = "@FltNo"
.Direction = adParamInput
.Type = adVarNumeric
.Size = 7
End With
Cmd.Parameters.Append oParam(0)

' Second Parameter
With oParam(1)
.Name = "@LegNo"
.Direction = adParamInput
.Type = adInteger
.Size = 4
End With
Cmd.Parameters.Append oParam(1)

' Third Parameter
With oParam(2)
.Name = "@EffTargetDate"
.Direction = adParamInput
.Type = adDate
.Size = 4
End With
Cmd.Parameters.Append oParam(2)

' Fourth Parameter
With oParam(3)
.Name = "@EndTargetDate"
.Direction = adParamInput
.Type = adDate
.Size = 7
End With
Cmd.Parameters.Append oParam(3)

' Fifth Parameter
With oParam(4)
.Name = "@SpendPerHead"
.Direction = adParamInput
.Type = adCurrency
.Size = 8
End With
Cmd.Parameters.Append oParam(4)

For k = 1 To flxgrid.Rows - 1
flxgrid.TextMatrix(k, 1) = Cmd.Parameters(0).Value
flxgrid.TextMatrix(k, 2) = Cmd.Parameters(1).Value
flxgrid.TextMatrix(k, 3) = Cmd.Parameters(2).Value
flxgrid.TextMatrix(k, 4) = Cmd.Parameters(3).Value
flxgrid.TextMatrix(k, 5) = Cmd.Parameters(4).Value
Cmd.Execute
Next

Set Cmd = Nothing
Set conSQL = Nothing

Exit Sub
ErrHand:
MsgBox (Err.Description)

End Sub



Stored Procedure:

CREATE PROCEDURE dbo.prcTargetLoad

@FltNo Varchar,
@LegNo Integer,
@EffTargetDate Datetime,
@EndTargetDate Datetime,
@SpendPerHead Float

AS



select FltNo From tblTargetSpendPerHead where FltNo = @FltNo
GO




thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top