0
votes

I am doing billing application, so I need to print a bill without Preview of Report. And, I don't like selecting a printer in a printer dialog popup. It should select the default printer.

'PrintToPrinter' is not working for my requirement. I need to send latest created BillID as parameter to get latest details.

If I don't use 'PrintToPrinter' syntax, the Printer dialog popup screen is coming with the "select printer" dialog.

Please guide me in solving this issue.

For your reference, I am attaching a snippet of my code:

Report_Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\Reports\\StandardBill.rpt";                        
ReportDocument rd = new ReportDocument();
rd.Load(Report_Path);
rd.SetDatabaseLogon(AccessingData.DBUserName, AccessingData.DBPassword);
ParameterFields paramFields = new ParameterFields();
ParameterField BillID = new ParameterField();
ParameterDiscreteValue discreteVal_BillID = new ParameterDiscreteValue();
BillID.ParameterFieldName = "BillNo";

discreteVal_BillID.Value = Convert.ToInt32(Bill_id);
BillID.CurrentValues.Add(discreteVal_BillID);

ParameterField CType = new ParameterField();
ParameterDiscreteValue discreteVal_CType = new ParameterDiscreteValue();
CType.ParameterFieldName = "ClientType";

discreteVal_CType.Value = ClientType;
CType.CurrentValues.Add(discreteVal_CType);

// Add parameter to the parameter fields collection.
paramFields.Add(BillID);
paramFields.Add(CType);
CRViewer1.ParameterFieldInfo = paramFields;

CRViewer1.ReportSource = rd;                        

CRViewer1.PrintReport();
rd.Close();
rd.Dispose();
1

1 Answers

0
votes

You can try with this

                Dim crtableLogoninfos As New TableLogOnInfos
                Dim crtableLogoninfo As New TableLogOnInfo
                Dim crConnectionInfo As New ConnectionInfo
                Dim CrTables As Tables
                Dim CrTable As Table
                Dim cryRpt As New ReportDocument
                cryRpt.Load("report path")
                With crConnectionInfo
                    .ServerName = "servername"
                    .DatabaseName = "databasename"
                    .UserID = "userid"
                    .Password = "password"
                    .IntegratedSecurity = False

                End With
                CrTables = cryRpt.Database.Tables
                For Each CrTable In CrTables
                    crtableLogoninfo = CrTable.LogOnInfo
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo
                    CrTable.ApplyLogOnInfo(crtableLogoninfo)
                Next
                cryRpt.SetDatabaseLogon("userid", crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.DatabaseName, crConnectionInfo.IntegratedSecurity)

                Dim crParameterFieldDefinitions As ParameterFieldDefinitions
                Dim crParameterFieldDefinition As ParameterFieldDefinition
                Dim crParameterValues As New ParameterValues
                Dim crParameterDiscreteValue As New ParameterDiscreteValue

                crParameterDiscreteValue.Value = BillID
                crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
                crParameterFieldDefinition = crParameterFieldDefinitions.Item("BillID")
                crParameterValues = crParameterFieldDefinition.CurrentValues
                crParameterValues.Add(crParameterDiscreteValue)
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
                crParameterValues.Clear()

                 cryRpt.PrintOptions.PrinterName = "printername"
                cryRpt.PrintToPrinter(1, False, 0, 0)


            End If

I think this should do the trick. It's in VB though.