I am creating an application using C# and MySQL. MySQL table (tbl_sales) has four fields(sale_item, sale_qty, added_n and last_updated_on). The data type of last updated_on field is DateTime. I want to display the records in the DataGridView according to the following SQL. SELECT * FROM tbl_sales WHERE last_updated_on >=" + dateTimePicker1.Text;
I got the following error You have and error in your SQL syntax; check the manual that corrosponds to yout MySQL server version for the right syntax to use near " at line 1
I used the following C# code
private void button1_Click(object sender, EventArgs e)
    {
        string query;
        try
        {
            conLocal.Open();
            query = "SELECT * FROM tbl_sales WHERE last_updated_on >=" + textBox1.Text; // Convert.ToString(dateTimePicker1.Text);
            cmdLocal = new MySqlCommand();
            cmdLocal.Connection = conLocal;
            cmdLocal.CommandText = query;
            da = new MySqlDataAdapter();
            da.SelectCommand = cmdLocal;
            dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            da.Dispose();
            conLocal.Close();
        }
}
 
 

 
     
     
    