Soluzione 1: utilizzando DateTime stringa
MySQL prende il DateTime nel seguente formato predefinito:
yyyy-MM-dd HH:mm:ss
così puoi convertire il tuo datetime oggetto nel format sopra .
Prova questo:
command.CommandText ="SELECT idGameNumber FROM GameOutcome WHERE GameOutcome.gameDate ='"+ game_time.ToString("yyyy-MM-dd HH:mm:ss")+"'";
Soluzione 2: utilizzando parameterised queries .
potresti aver già sentito parlare di parameterised queries .
Le query parametrizzate non solo evitano sql injection attacks forniscono anche un modo pulito per inviare/passare arguments ai campi nella tabella.
command.CommandText ="SELECT idGameNumber FROM GameOutcome WHERE GameOutcome.gameDate example@sqldat.com;"
command.Parameters.AddWithValue("@gamedate",game_time);