The problem is converting the string values to dates. To accomplish this you should use an actual SqlCommand and SqlParameters (to prevent SQL injection). You are also going to need to convert the values the user entered in a the text box to DateTime objects. You should also use Between in your WHERE clause instead of <>.
Your code should look similar to this:
*** Note: I just typed this into the browser so it probably wont compile ***
private void button1_Click(object sender, EventArgs e)
{
string from_date = textBox1.Text ;
string to_date = textBox2.Text;
DataSet ds1 = new DataSet();
ReportDocument cr = new ReportDocument();
using (SqlConnection con=new SqlConnection (@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True")){
String data = "SELECT * from Product where dat BETWEEN @StartDate AND @EndDate";
con.Open();
using (SqlCommand cmd = new SqlCommand(data, conn))
{
cmd.Parameters.Add(new SqlParameter("@StartDate", Convert.ToDateTime(from_date));
cmd.Parameters.Add(new SqlParameter("@EndDate", Convert.ToDateTime(to_date));
using (SqlDataAdapter ad1 = new SqlDataAdapter(cmd))
{
ad1.Fill(ds1);
}
}
}
cr.Load(@"C:\Users\Ahmed\Documents\Visual Studio 2010\Projects\WindowsFormsApplication9\WindowsFormsApplication9\CrystalReport4.rpt");
cr.SetDataSource(ds1.Tables["product"]);
crystalReportViewer1.ReportSource = cr;
}
You should probably read up on this stuff so here are some links:
SQL Between Operator[
^]
SqlCommand Class[
^]
SqlParameter Class[
^]
C# using Statement[
^]
DateTime.TryParseExact[
^]
Convert.ToDateTime[
^]