0
votes

In my project, I have a button that, when clicked, is supposed to print all contracts that are currently active, from my SQL Server database. There are hundreds of active contracts, but at the moment, when I press the button, the report form loads but the report doesn't.

I'll do my best to demonstrate this using images and code, but is anybody able to suggest why this happens?

// Code for the print button

 Private Sub btnPrintActive_Click(sender As Object, e As EventArgs) Handles btnPrintActive.Click

    Try
        Dim objlist As New ReportDocument
        objlist.Load(readIni("REPORTS", directorypath & "connectionpaths.ini") & "\ContractList.rpt")

        Dim info As CrystalDecisions.Shared.TableLogOnInfo
        info = New CrystalDecisions.Shared.TableLogOnInfo()

        info.ConnectionInfo.DatabaseName = ""
        info.ConnectionInfo.ServerName = readIni("CONTRACTSTRING", directorypath & "connectionpaths.ini")
        info.ConnectionInfo.Password = ""
        info.ConnectionInfo.UserID = ""
        objlist.Database.Tables(0).ApplyLogOnInfo(info)

        objlist.RecordSelectionFormula = "{tblContracts.Agreement} = 'ACTIVE'"

        Dim f As frmReports
        f = New frmReports(con, acccon, "", 0, "", acccon, , objlist, , )
        f.Show()

    Catch ex As Exception
        errorLog(ex.Message, ex.StackTrace)
        MsgBox("Failed to retrieve contract information from 'database', refer to error log")
    End Try

End Sub

// This is the report form, but there is no report

enter image description here

// Proof that there are active reports

enter image description here

2
Is this a brand new form/report, that has never worked, or one that suddenly is no longer working?Ann L.
Because the form is not showing a report, rather than showing a report with no data, have you verified that a) the .rpt file is where the app is looking for it, and b) that frmReports is loading it? We might need to see the constructor in frmReports.Ann L.
helloo @David.. is this resolved?Vijunav Vastivch
@AnnL. Hi, no this was working before, then I changed the database over from Access to SQLServer, and when making the code changes it stopped working. Two of my reports work, but some do not, so I was hoping the same problem would fix them allDavid
@reds Hi, no this is still brokenDavid

2 Answers

0
votes

This is now fixed. The problem was that I was using 2 database tables in my reports, but was only providing the login information for 1, and the second one wasn't receiving the data from the server, hence why it didn't display. The other thing I did, was changed the fact it was logging in with blank values. My fixed code is now this;

 Private Sub btnPrintActive_Click(sender As Object, e As EventArgs) Handles btnPrintActive.Click

    Try
        Dim objlist As New ReportDocument
        objlist.Load(readIni("REPORTS", directorypath & "connectionpaths.ini") & "\ContractList.rpt")

        Dim info As CrystalDecisions.Shared.TableLogOnInfo
        info = New CrystalDecisions.Shared.TableLogOnInfo()

        Dim servername As String = (readIni("SQLConnection", directorypath & "connectionpaths.ini", "servername"))
        Dim database As String = (readIni("SQLConnection", directorypath & "connectionpaths.ini", "database"))
        Dim username As String = (readIni("SQLConnection", directorypath & "connectionpaths.ini", "username"))
        Dim password As String = (readIni("SQLConnection", directorypath & "connectionpaths.ini", "password"))
        Dim provider As String = (readIni("SQLConnection", directorypath & "connectionpaths.ini", "provider"))

        info.ConnectionInfo.DatabaseName = database
        info.ConnectionInfo.ServerName = servername
        info.ConnectionInfo.Password = password
        info.ConnectionInfo.UserID = username

        objlist.Database.Tables(0).ApplyLogOnInfo(info)
        objlist.Database.Tables(1).ApplyLogOnInfo(info)

        objlist.RecordSelectionFormula = "{tblContracts.Agreement} = 'ACTIVE'"

        Dim f As frmReports
        f = New frmReports(con, acccon, "", 0, "", acccon, , objlist, , )
        f.Show()

    Catch ex As Exception
        errorLog(ex.Message, ex.StackTrace)
        MsgBox("Failed to retrieve contract information from database, refer to error log")
    End Try

End Sub
0
votes

Try to compare this one:

 try
            {

                String APPPATH = String.Empty;
                CRPT = new ReportDocument();
                APPPATH = System.IO.Directory.GetCurrentDirectory() + "/CrystalReport/CrystalReport1.rpt";
                //APPPATH = "~/Crystal_report/mosum.rpt";
                CRPT.Load(APPPATH);
                crViewer.RefreshReport();

                CLASS_PROJECT.crystalReportcls rptcls = new CLASS_PROJECT.crystalReportcls();

                ParameterFields paramFields = new ParameterFields();
                ParameterField paramField = new ParameterField();
                ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
                paramField.Name = "sdate";
                paramDiscreteValue.Value = "2016-07-01";
                paramField.CurrentValues.Add(paramDiscreteValue);
                paramFields.Add(paramField);


                crViewer.ParameterFieldInfo = paramFields;
                crViewer.ReportSource = CRPT;


                MessageBox.Show("Crystal logged in.");
                CRPT.SetDatabaseLogon("dbusername", "dbpassword");
                rptcls.LogonCrystalReport(crViewer);

            }
            catch (Exception er)
            {

                MessageBox.Show(er.Message);
            }

this structure is working for my sample. all you have to do is login the crystal report and the report path itself.