troubleshooting Question

how do i pass parameters into crystal via vb.net

Avatar of bschave2
bschave2 asked on
Crystal ReportsVisual Basic.NET
5 Comments2 Solutions408 ViewsLast Modified:
i have a crystal report where I am grabbing employee data and i have the dsnless connection working fine, but when I try to take add a parameter, I get the following error:

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
Public Sub RptParameters()
        conn.Open()
 
        Dim param As String = "3"
 
        If Request.QueryString("param") = "1" Then
 
            cmd = New MySqlCommand("select * from emp_benefit_info as eb left join employees as e on eb.user_id = e.userID order by eb.name asc", conn)
            da = New MySqlDataAdapter(cmd)
            ds = New DataSet()
            da.Fill(ds, "emp_benefit_info")
            Session("crystal_param") = "no"
            report.Load(Server.MapPath("completed_report.rpt"))
 
        ElseIf Request.QueryString("param") = "2" Then
 
            cmd = New MySqlCommand("select name from employees where name not in (select name from emp_benefit_info) order by name asc", conn)
            da = New MySqlDataAdapter(cmd)
            ds = New DataSet()
            da.Fill(ds, "employees")
            Session("crystal_param") = "no"
            report.Load(Server.MapPath("incomplete_report.rpt"))
 
        ElseIf param = "3" Then
 
            cmd = New MySqlCommand("select * from emp_benefit_info as eb left join employees as e on eb.user_id = e.userID order by eb.name asc", conn)
            da = New MySqlDataAdapter(cmd)
            ds = New DataSet()
            da.Fill(ds, "emp_benefit_info")
            Session("crystal_param") = "yes"
            report.Load(Server.MapPath("completed_report.rpt"))
 
        End If
    End Sub
 
RptParameters()
 
Dim myTableLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
        Dim myConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
        myConnectionInfo.AllowCustomConnection = True
        myConnectionInfo.ServerName = mySQLserver
        myConnectionInfo.DatabaseName = "www_extranet_dev"
        myConnectionInfo.UserID = "bschave"
        myConnectionInfo.Password = passWord
        Dim myTables As CrystalDecisions.CrystalReports.Engine.Tables
 
        myTables = report.Database.Tables 'old line: myReport.Database.Tables
        For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
            myTableLogonInfo = myTable.LogOnInfo
            myTableLogonInfo.ConnectionInfo = myConnectionInfo
            myTable.ApplyLogOnInfo(myTableLogonInfo)
        Next
 
        If Session("crystal_param") <> "no" Then
 
            Try
                report.SetParameterValue("user_id", Session("NTLOGON").ToString())
            Catch ex As Exception
                lblError.Text = ex.Message
            End Try
 
            Dim s As String
            s = Session("NTLOGON").ToString()
 
            report.SetParameterValue("user_id", s)
        End If
        'report.SetParameterValue("contractno", ctrNo)
        'report.SetParameterValue("trantype", tranType)
        'report.SetParameterValue("proddt", prodDate)
        CrystalReportViewer1.ReportSource = report 'old line: myReport
        CrystalReportViewer1.DataBind()
ASKER CERTIFIED SOLUTION
bschave2

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros