hello sir,
I have refer your post as below link.
I try to print crystal report but some point I’m not getting kindly help me to solve it.
In below article I have seen this below code I’m not getting The Private Customers and .ds how to use where to use.
In my application I want to print record separately like save and print current record which is being save.
ReportDocument crystalReport = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));
Customers dsCustomers = GetData();
crystalReport.SetDataSource(dsCustomers);
CrystalReportViewer1.ReportSource = crystalReport;
CrystalReportViewer1.DisplayGroupTree = false;
}
private Customers GetData()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT CustomerId,ContactName,City,Country FROM Customers";
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Customers ds = new Customers())
{
sda.Fill(ds, "DataTable1");
return ds;
}
}
}
}
protected void Print(object sender, EventArgs e)
{
// Refresh Report.
crystalReport.Refresh();
// Set Paper Orientation.
crystalReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
// Set Paper Size.
crystalReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
// CrystalDecisions.Shared.ExportFormatType to change the format i.e. Excel, Word, PDF
//crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "CustomerDetails");
crystalReport.PrintOptions.PrinterName = GetDefaultPrinter();
crystalReport.PrintToPrinter(1, true, 0, 0);
}
private string GetDefaultPrinter()
{
PrinterSettings settings = new PrinterSettings();
foreach (string printer in PrinterSettings.InstalledPrinters)
{
settings.PrinterName = printer;
if (settings.IsDefaultPrinter)
{
return printer;
}
}
return string.Empty;
}