Gopal
Gopal

Reputation: 11972

How to pass the parameter to stored procedure

Using Crystal Report 9 and VB.Net

Report is running through stored procedure, I want to pass the data to stored procedure.

How to do it?

In VB6, i did like this.

Report.ReportFileName = REPPATH & "\Detail.rpt"
Report.StoredProcParam(0) = Did
Report.StoredProcParam(1) = Deed
Report.Action = 1

How to do it in vb.net?

Upvotes: 0

Views: 5310

Answers (1)

Minus
Minus

Reputation: 729

I think something like the following should work:

SetDataSource have like 4 overrides that all take an IEnumerable like object as parameter. But this has been done with CR 13 for VS 2010... I hope you will find something like with CR 9.

    Dim report As New CrystalReport1
    Dim sqla = New SqlDataAdapter()
    sqla.SelectCommand.Connection = New SqlConnection(sConnectionString)
    sqla.SelectCommand = New SqlCommand("EXEC storedProcName @a, @b, @c")
    sqla.SelectCommand.Parameters.Add("@a", paramA)
    sqla.SelectCommand.Parameters.Add("@a", paramB)
    sqla.SelectCommand.Parameters.Add("@a", paramC)

    report.SetDataSource(sqla)
    //'If you do not have parameters, you may use :
    report.SetDataSource(New SqlDataAdapter("EXEC storedProcName ", sConnectionString))

    report.Refresh()

EDIT : sqla.SelectCommand.Parameters.Add("@a", paramA) is depreciated in the CR13 version. sqla.SelectCommand.Parameters.AddWithValue("@a", paramA) is used instead.

Upvotes: 2

Related Questions