Krishna

Krishna

  • NA
  • 5
  • 1.5k

Validate the From date and To date in asp.net using C#??

Jul 7 2016 12:31 AM
export raw data in MS excel from sql database 
 
input parameter
1. date period (from date ~ todate  and today,yesterday,month ) 
2. search ID 
 
  1. public partial class WebForm1 : System.Web.UI.Page  
  2.    {  
  3.   
  4.        protected void Page_Load(object sender, EventArgs e)  
  5.        {  
  6.           
  7.        }  
  8.   
  9.        protected void ExportExcel(object sender, EventArgs e)  
  10. {  
  11.            string storeNo = StoreNo.Text;  
  12.              
  13.          using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MakaseteNet_V1ConnectionString"].ConnectionString))  
  14.            {  
  15.                using (SqlCommand cmd = new SqlCommand("SELECT * FROM POS_TtlTran where StoreNo = " + storeNo))  
  16.                {  
  17.   
  18.                    using (SqlDataAdapter sda = new SqlDataAdapter())  
  19.                    {  
  20.                        cmd.Connection = con;  
  21.                        sda.SelectCommand = cmd;  
  22.                        using (DataTable dt = new DataTable())  
  23.                        {  
  24.                            sda.Fill(dt);  
  25.                            using (XLWorkbook wb = new XLWorkbook())  
  26.                            {  
  27.                                wb.Worksheets.Add(dt, "StoreNo");  
  28.   
  29.                                Response.Clear();  
  30.                                Response.Buffer = true;  
  31.                                Response.Charset = "";  
  32.                                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";  
  33.                                Response.AddHeader("content-disposition""attachment;filename=POS_TtlTran.xlsx");  
  34.                                using (MemoryStream MyMemoryStream = new MemoryStream())  
  35.                                {  
  36.                                    wb.SaveAs(MyMemoryStream);  
  37.                                    MyMemoryStream.WriteTo(Response.OutputStream);  
  38.                                    Response.Flush();  
  39.                                    Response.End();  
  40.                                }  
  41.                            }  
  42.                        }  
  43.                    }  
  44.                }  
  45.            }  
  46.        }  
  47.   
  48.    }  
  49.  }  
  1. <body>  
  2.     <form id="form1" runat="server">  
  3.           
  4.     <div>  
  5.   <td>  
  6.      <tr>  
  7.              StoreNO <asp:TextBox ID="StoreNo" runat="server"  ></asp:TextBox>  
  8.      </tr>  
  9.  </td>  
  10.  <br>  
  11.  <br>  
  12.    <td class="auto-style11" colspan="2">  
  13.            <asp:Label ID="Date" runat="server" Text="Date" meta:resourcekey="lbFromMonthResource1"></asp:Label>  
  14.              <asp:TextBox ID="FromMonth" runat="server" Width="90px" class="date-picker" meta:resourcekey="tbxFromMonthResource"></asp:TextBox>  
  15.    </td>  
  16.     <td id="td1">~<asp:TextBox ID="ToMonth" runat="server" Width="90px" class="date-picker" meta:resourcekey="tbxToMonthResource"></asp:TextBox>  
  17.            </td>  
  18.  </br><br>  
  19.         <input id="btnToday" type="button" value="Today" class="btn btn-default" />  
  20.             <input id="btnYesterday" type="button" value="Yesterday" class="btn btn-default" />  
  21.              <input id="btnThisMonth" type="button" value="ThisMonth" class="btn btn-default" />  
  22.     </br>  
  23.       <br>         
  24.           <asp:Button Text="Export to excel" OnClick="ExportExcel" runat="server" />  
  25.           </br>  
  26.         </div>  
  27.     </form>  
  28. </body>  
  29. </html>  
 Can anyone help how to do it !

Answers (2)