Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Data.SqlClient;
  11.  
  12. using CrystalDecisions.CrystalReports.Engine;
  13. using CrystalDecisions.Shared;
  14.  
  15. namespace Test1
  16. {
  17.     public partial class CrystalReportSimple : System.Web.UI.Page
  18.     {
  19.         protected void Page_Load(object sender, EventArgs e)
  20.         {
  21.  
  22.         }
  23.  
  24.         protected void Page_Init(object sender, EventArgs e)
  25.         {
  26.             ReportDocument crystalReport = new ReportDocument();
  27.             crystalReport.Load(Server.MapPath("~/CrystalReportStandard.rpt")); // .rpt file path
  28.             Bookings dsBookings = GetData("SELECT Bookings.BookingID, Bookings.BookingDate, CurrentProducts.ProductID, CurrentProducts.ProductName, Customer.LastName, Customer.FirstName, Bookings.NumberOfGuests" +
  29.                                                 " FROM Bookings INNER JOIN" +
  30.                                                 " CurrentProducts ON Bookings.ProductID = CurrentProducts.ProductID INNER JOIN" +
  31.                                                 " Customer ON Bookings.CustomerID = Customer.CustomerID");
  32.             crystalReport.SetDataSource(dsBookings.Tables[0]); //set dataset to the report viewer
  33.             CrystalReportViewer1.ReportSource = crystalReport;
  34.             CrystalReportViewer1.DataBind();
  35.         }
  36.  
  37.         private Bookings GetData(string query)
  38.         {
  39.             string conString = ConfigurationManager.ConnectionStrings["JProCoConnectionString"].ConnectionString;
  40.             SqlCommand cmd = new SqlCommand(query);
  41.             using (SqlConnection con = new SqlConnection(conString))
  42.             {
  43.                 using (SqlDataAdapter sda = new SqlDataAdapter())
  44.                 {
  45.                     cmd.Connection = con;
  46.  
  47.                     sda.SelectCommand = cmd;
  48.                     using (Bookings dsBookings = new Bookings())
  49.                     {
  50.                         sda.Fill(dsBookings, "DataTable1");
  51.                         return dsBookings;
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement