1
Did you put a debug point on this line and checked what is the value of the "sql" string?
Ideally you shold be able to run that "Sql" string as a query as it is in SQL Server.
First try to fix it. Until you are not able to get the result in SQL this way, your code will not work.
I suspect here the Value.toString() is producing some date with unexpected format or with date time and seconds fractions.
try to create date in YYYY-MM-DD format from the datepicker first.
Accepted 1
Dear Sir, How can I get data of selected date? I always get the between value. If i use AddDays(-1) and select 1st date of any month, I get previous month's data. I do not use sql server here. It is desktop application with access database. I am new in C#.
private void btnSearch_Click(object sender, EventArgs e)
{
con = new OleDbConnection(conString);
string sql = "SELECT * FROM LalData WHERE PaymentDate between '"+ dtpStartDate.Value.AddDays(-1).ToString() + "' AND '" + dtpEndDate.Value.ToString()+"'";
con.Open();
adapter = new OleDbDataAdapter(sql, con);
dt = new DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];
btnSubmit.Enabled = false;
}