Crystal report - OLE DB con - asp.net (02)

Best way

* Add crystal report.
* Add data set(Under add new item to the project).
* Add data table to to data set.
*Add relevant column to data table you want to retrieve from the DB table to.
* Go to crystal report.
* Right click on crystal report.
*
* Click next and add whatever fields to your report as it mentioned.
*Then go to button which has to show the crystal report.
* Buttonclick event is below....
------------------------------------------
      protected void Button1_Click1(object sender, EventArgs e)
        {//View sales report
            
            if ( !DropDownList2.SelectedValue.Equals("Month"))
            {
                
                string month = DropDownList2.SelectedValue.ToString();
                CrystalReportViewer1.Visible = true;
                
                DataSet ds = new DataSet();
                ds = LoadSpngCart(month);//call to below method
                CrystalReportViewer1.Visible = true;
                CrystalReport1 myRep = new CrystalReport1();
                myRep.SetDataSource(ds);
                CrystalReportViewer1.ReportSource = myRep;
            }
            else { Response.Write("Please select date properly"); }
        }
        public DataSet LoadSpngCart(string month)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand("SELECT MainSID,PName,Qunatity from SubShoppingCart where AddDate ='"+month+"' ", DBConnect()))
                {
                    DataSet ds = new DataSet();
                    SqlDataAdapter adpterToViewCartDetails = new SqlDataAdapter(cmd);
                    adpterToViewCartDetails.Fill(ds, "DataTable1");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        return ds;
                    } return null;
                }
            }
            catch (Exception report_error) { Response.Write("No data regarding what you are required !!! "); return null; }

        }


-----------------------


Comments

Popular Posts