Shovan Saha

Shovan Saha

  • NA
  • 321
  • 91.9k

StartDate and EndDate data select in datagridview

Mar 18 2017 4:28 PM
I have MS access database and form C# windows application managed by visual studio 2015. PaymentDate is a column name. I want to select from datagridview StartDate and EndDate with text box or datetimepicker using search button. But within a month it is good. But when I select one month to another month then it select full database. Here is my code:
private void btnSearch_Click(object sender, EventArgs e)
{
con = new OleDbConnection(conString);
string sql = "SELECT * FROM LalData WHERE PaymentDate between '" + txtStartDate.Text.ToString() + "' AND '" + txtEndDate.Text.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;
}

Answers (2)