Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable objDataTable = MatrimonialSales.GetSalesReport();
        DB2Excel  objExport    = new DB2Excel();

        objExport.Export(objDataTable, DB2Excel.ExportFormat.Excel, "Query_Results_." + DateTime.Now.ToShortDateString() + ".xls");
        Server.Transfer("~/Admin/Protected/SaleReport.aspx");
    }
    protected void B_SaveExcel_Click(object sender, EventArgs e)
    {
        if (HF_Query.Value != "")
        {
            try
            {
                string strSQL = TB_SQL_Query.Text.Trim();
                using (SqlConnection objConnection = DBConnection.GetSqlConnection())
                {
                    //Database Operations
                    SqlDataAdapter objAdapter = new SqlDataAdapter(strSQL, objConnection);
                    DataSet        objDataSet = new DataSet();

                    // OpenConnection
                    objConnection.Open();

                    objAdapter.Fill(objDataSet, "ResultSet");
                    //Load Control
                    // Close Connection
                    objConnection.Close();

                    DataTable objDataTable = objDataSet.Tables["ResultSet"].Copy();

                    // DB2Excel all the details to Excel
                    DB2Excel objExport = new DB2Excel();
                    objExport.Export(objDataTable, DB2Excel.ExportFormat.Excel, "Query_Results_." + DateTime.Now.ToShortDateString() + ".xls");
                }
            }
            catch (System.Data.SqlClient.SqlException SqlEx)
            {
                L_QueryError.Visible = true;
                ErrorLog.WriteErrorLog("Admin-Protected-QueryChecker", SqlEx);
            }
            catch (Exception Ex)
            {
                ErrorLog.WriteErrorLog("Admin-Protected-QueryChecker", Ex);
                L_QueryError.Visible = true;
            }
        }
        else
        {
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                using (SqlConnection objConnection = DBConnection.GetSqlConnection())
                {
                    SqlCommand objCommand = new SqlCommand("Matrimonials_DataBaseDetails", objConnection);
                    objCommand.CommandType = CommandType.StoredProcedure;

                    //Database Operations
                    // Open Connection
                    objConnection.Open();
                    SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
                    DataSet        objDataSet = new DataSet();
                    // Close Connection
                    objConnection.Close();
                    objAdapter.Fill(objDataSet, "ResultSet");
                    GV_Query.DataSource = objDataSet;
                    GV_Query.DataBind();
                }
            }
            catch (Exception Ex)
            {
                ErrorLog.WriteErrorLog("Admin-Protected-MatrimonialDatabase", Ex);
                L_QueryError.Visible = true;
            }
        }
        else
        {
            try
            {
                using (SqlConnection objConnection = DBConnection.GetSqlConnection())
                {
                    SqlCommand objCommand = new SqlCommand("Matrimonials_DataBaseDetails", objConnection);
                    objCommand.CommandType = CommandType.StoredProcedure;

                    //Database Operations
                    // Open Connection
                    objConnection.Open();
                    SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
                    DataSet        objDataSet = new DataSet();
                    objAdapter.Fill(objDataSet, "ResultSet");

                    //Save AS Excel

                    // Open Connection
                    objConnection.Close();
                    DataTable objDataTable = objDataSet.Tables["ResultSet"].Copy();

                    // DB2Excel all the details to Excel
                    DB2Excel objExport = new DB2Excel();
                    objExport.Export(objDataTable, DB2Excel.ExportFormat.Excel, "Query_Results_." + DateTime.Now.ToShortDateString() + ".xls");
                }
            }
            catch (Exception Ex)//Oops Some Error Had Happend
            {
                ErrorLog.WriteErrorLog("Admin-Protected-Matrimonial Database", Ex);
                L_QueryError.Visible = true;
            }
        }
    }