chinedu Nwankwo

chinedu Nwankwo

  • NA
  • 94
  • 29.1k

How to display data between two dates in asp.net C#

Feb 25 2017 11:42 AM
Please help i am trying to display data between two dates using the report viewer as well an a jquery datepicker below is my code  but it keeps throwing up the error message

Please what is wrong thanks   
 
 Chinedu Nwankwo
 
protected void Btnsearch_Click(object sender, EventArgs e)
{
try
{
// based on the scenerio of the check button disable the pinnumber button then call the various classes for the reports
IFormatProvider enGBDateFormat = new CultureInfo("en-GB").DateTimeFormat;
Convert.ToDateTime(txtstartdate.Text, enGBDateFormat);
Convert.ToDateTime(txtEndDate.Text, enGBDateFormat);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbs"].ConnectionString);
con.Open();
SqlCommand cmd;
//SqlCommand cmd3;
String sql = "select * from BILLING_TAB where PIN_NUM LIKE '@pinnum' AND BILL_DAT between @startdate AND @enddate";
cmd = new SqlCommand(sql, con);
// cmd.CommandType = CommandType.StoredProcedure;
//string branchcode = drpbranch.SelectedValue;
cmd.Parameters.Add("@pinnum", SqlDbType.VarChar).Value = txtpin.Text;
cmd.Parameters.Add("@startdate", SqlDbType.DateTime).Value = Convert.ToDateTime(txtstartdate.Text, enGBDateFormat);
cmd.Parameters.Add("@enddate", SqlDbType.DateTime).Value = Convert.ToDateTime(txtEndDate.Text, enGBDateFormat).AddDays(1);
cmd.ExecuteNonQuery();
SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds, "DataSet4");
DataTable dt = new DataTable();
dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
lblmessage.Text = "Loading.....";
}
else
{
lblmessage.Text = "No records found...";
//btnUpload.Visible = false;
// ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert('No record found ');", true);
}
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/BillingReport.rdlc");
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet4", ds.Tables[0]));
//ReportParameter startdate = new ReportParameter("startDate", Convert.ToDateTime(txtStartDate.Text, enGBDateFormat).ToString());
//tryBalancerpt.LocalReport.SetParameters(new ReportParameter[] { startdate });
//ReportParameter enddate = new ReportParameter("enddate", Convert.ToDateTime(txtEndDate.Text, enGBDateFormat).ToString());
//tryBalancerpt.LocalReport.SetParameters(new ReportParameter[] { enddate });
ReportViewer1.LocalReport.Refresh();
con.Close();
}
catch (Exception ex)
{
}
}
}
 
 
 
 
 

Answers (2)