The code below Works ok; from 01st to 12th of every month; However as soon as I click on 13th or greater date I Get this error
Conversion failed when converting date and/or time from character string.
This my Code
DateTime dt = Convert.ToDateTime(Calendar1.SelectedDate.ToString("yyyy-MM-dd"));
myConnection.Open();
string cmdStr1 = "SELECT COUNT(*) FROM Payment WHERE PaymentDate = '" + dt + "'";
SqlCommand PIDexist1 = new SqlCommand(cmdStr1, myConnection);
int temp1 = Convert.ToInt32(PIDexist1.ExecuteScalar().ToString());
myConnection.Close();
Thank for your Help
This is How Date is saved in my Database 2012-01-13
No, never bind dates like that. Let the .NET data provider handle this for you – there are just way too many pitfalls with locales on the App and Sql Server for you to use strings as dates.