By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,173 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,173 IT Pros & Developers. It's quick & easy.

How to pass parameter to sub report in crystal report run time?

P: 1
I am developing web application in VB.net. I want to use crystal reports in my application. I want to add subreports to main report and want to pass parameters to subreports. Can I get sample code to do that?
Jan 17 '08 #1
Share this Question
Share on Google+
1 Reply


P: 1
I am developing web application in VB.net. I want to use crystal reports in my application. I want to add subreports to main report and want to pass parameters to subreports. Can I get sample code to do that?

Dim myCon As New SqlClient.SqlConnection()
myCon.ConnectionString = ConfigurationManager.ConnectionStrings("MyCon").Co nnectionString
Dim mycmd As New SqlClient.SqlCommand()
Dim mycmd1 As New SqlClient.SqlCommand
mycmd.Connection = myCon
mycmd1.Connection = myCon
' For Stored Procedure
mycmd.CommandType = CommandType.StoredProcedure
mycmd.CommandText = "Depo_InvoicePrint"
mycmd.Parameters.Add("@CompanyId", SqlDbType.VarChar)
mycmd.Parameters("@CompanyId").Value = Session("CompanyID")

mycmd1.CommandType = CommandType.StoredProcedure
mycmd1.CommandText = "Depo_InvoicePrintSubreport"
mycmd1.Parameters.Add("@DepotID", SqlDbType.VarChar)
mycmd1.Parameters("@DepotID").Value = Session("DepotID")

Dim myda As New SqlClient.SqlDataAdapter()
myda.SelectCommand = mycmd
Dim myDs As New DataSet()
myda.Fill(myDs, "InvoicePrint")

Dim myda1 As New SqlClient.SqlDataAdapter()
myda1.SelectCommand = mycmd1
Dim myDs1 As New DataSet()
myda1.Fill(myDs1, "InvoicePrintSubreport")

mycmd.Dispose()
mycmd1.Dispose()
myCon.Close()

oRpt.Load(Server.MapPath(c:/rptInvoicePrint.rpt"))
oRpt.FileName = Server.MapPath(c:/rptInvoicePrint.rpt")
oRpt.SetDataSource(myDs)
oRpt.OpenSubreport("rptInvoicePrintSub").SetDataSo urce(myDs1)

oRpt.SetParameterValue("@CompanyID", Session("CompanyID"))
oRpt.SetDatabaseLogon(Session("dbuser"), Session("dbpass"))

oRpt.SetParameterValue("@DepotID", Session("DepotID"), "rptInvoicePrintSub")

myCon.Close()
End Sub
Mar 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.