skip to Main Content

I think the problem is in the format.
I have this code in the class:

public DataTable CheckDate(DateTime day)
    {
        MySqlCommand command = new MySqlCommand("SELECT * FROM `appuntamenti` WHERE `date`='@date'", conn.getConnection());
        command.Parameters.Add("@date", MySqlDbType.Date).Value = date;
        MySqlDataAdapter adapter = new MySqlDataAdapter();    
        DataTable table = new DataTable();
        adapter.SelectCommand = command;
        adapter.Fill(table);
        return table;
    }

e in the form c#, i use:

private void button2_Click(object sender, EventArgs e)
    {          
        DateTime day = dateTimePicker2.Value;
        dataGridView1.DataSource = appuntamento.CheckDate(day);

    }

When i click the button2, it is generate the query and the empty filtered table are generated.
The format in database is YYYY-MM-GG but in visual studio the format is GG-MM-YYYY.
I change the format in YYYY-MM-GG but it create an unusual bug (i click on datatimepicker 24/04/2020 but the output datatimepicker is 2020-00-24). When i use my query on localhost/phpmyadmin, it works.
Can you help me?

2

Answers


  1. Try removing the quotes from around @date.

    The PDO statement should handle the rest

    Login or Signup to reply.
  2. Remove all quotes in the query.

    Like this:

    "SELECT * FROM appuntamenti WHERE date = @date"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search