My code is not working for date wise filter record and bind to gridview. giving error
Conversion failed when converting date and/or time from character string.
my code is
- protected void btnShow_Click(object sender, EventArgs e)
- {
- try
- {
-
- SqlCommand cmd = new SqlCommand("select * from OrraStock_Sales where createDate between '@fromDt' and '@toDt'", con);
- cmd.Parameters.AddWithValue("@fromDt",txtFromDt.Text);
- cmd.Parameters.AddWithValue("@toDt",DateTime.Parse(txtToDt.Text));
- con.Open();
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- ds = new DataSet();
- da.Fill(ds);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- lblTotRecord.Text = "" + ds.Tables[0].Rows.Count;
- con.Close();
- }
- catch (Exception ex)
- { Response.Write(ex.Message); }
- }
Please help me.