Using Strongly Typed DataSet in Crystal Reports using C# and VB.Net in ASP.Net

on Jan 12, 2021 10:53 PM

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.

Print all pages from Crystal Report on Button click using C# and VB.Net in ASP.Net

ReportDocument crystalReport = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
    Customers dsCustomers = GetData();
    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.
    // 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;


Download FREE API for Word, Excel and PDF in ASP.Net: Download