Click here to Skip to main content
15,867,288 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,


On a page i m filtering data by two dates those are taken from two text boxes
when the month is same in both text boxes but when i change my month then did not give any thing
Posted
Comments
shijuse 25-Jul-12 7:00am    
Please Check your query .I think problem with your query
OriginalGriff 25-Jul-12 7:01am    
How are you filtering it?
Are you creating an SQL statement?
Pradeep_kaushik 25-Jul-12 7:04am    
yes i m creating an sql statement
Muhammad Shahid Farooq 25-Jul-12 7:03am    
Share your code
Pradeep_kaushik 25-Jul-12 7:05am    
here is the code

protected void Button1_Click1(object sender, EventArgs e)
{
DateTime dt1 = Convert.ToDateTime(TextBox1.Text);
DateTime dt2 = Convert.ToDateTime(TextBox2.Text);
con.Open();

SqlDataAdapter da = new SqlDataAdapter("select 'Ch.No'=SNO,'Date'=DATE,'Particulars'=PNAME,'Qty'=QUANT,'Rate'=RATE,'Amount'=TOTAL,'Balance'=BALANCE from BILL1 where CNAME='" + DropDownList1.SelectedItem.Text + "' and DATE between '" + dt1.ToShortDateString() + "' and '" + dt2.ToShortDateString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
Button3.Visible = true;
}

1 solution

Hi,
Try this:
C#
protected void Button1_Click1(object sender, EventArgs e) 
{ 
    DateTime dt1 = Convert.ToDateTime(TextBox1.Text); 
    DateTime dt2 = Convert.ToDateTime(TextBox2.Text); 
    con.Open(); 
    SqlCommand cmd = new SqlCommand("select 'Ch.No'=SNO,'Date'=DATE,'Particulars'=PNAME,'Qty'=QUANT,'Rate'=RATE,'Amount'=TOTAL,'Balance'=BALANCE from BILL1 where CNAME=@Cname and DATE between @FromDate and @ToDate", con)
    cmd.CommandType = CommandType.Text;
    cmd.Parameters.add("@Cname", DropDownList1.SelectedItem.Text);
    cmd.Parameters.add("@FromDate", dt1);
    cmd.Parameters.add("@ToDate", dt2);
    SqlDataAdapter da = new SqlDataAdapter(cmd); 
    DataSet ds = new DataSet(); 
    da.Fill(ds); 
    GridView1.DataSource = ds; 
    GridView1.DataBind(); 
    con.Close(); 
    Button3.Visible = true; 
}



All the best.
--Amit
 
Share this answer
 
Comments
Pradeep_kaushik 25-Jul-12 7:28am    
it gives an error

Arithmetic overflow error converting expression to data type datetime.
_Amy 25-Jul-12 7:32am    
Then check the type of your table column. It is varchar there in your table.
Pradeep_kaushik 25-Jul-12 7:36am    
its nvarchar
_Amy 25-Jul-12 7:40am    
Change it to datetime.. It'll work.. And one advise, Always keep correct data type into your table. You'll never get any problem..
Pradeep_kaushik 25-Jul-12 7:44am    
ok sir thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900