In my application I want to count the number of records with the same current year and month. So my logic is to compare the current Year and Month to the date_needed column in my table. Here's how I did it:
using (MySqlConnection con = new MySqlConnection(serverstring))
{
con.Open();
string query = "SELECT * FROM tblOrder WHERE date_needed=@dateTimeNow";
using (MySqlCommand cmd = new MySqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@dateTimeNow", DateTime.Now.ToString("yyyy-MM")); using (MySqlDataReader dr = cmd.ExecuteReader())
{
int count = 0;
while (dr.Read())
{
count++;
}
MessageBox.Show(count.ToString());
}
}
}
I know that it doesn't work because in my messagebox it shows zero instead of one record. What do you think is the problem?