I’m trying to insert a date into a MSSQL database its fails with an error - converting datetime to character string
The code it s something wrong with strsql
int insertResult;
string ConnString;
string strsql;
SqlConnection cnSQL;
SqlCommand cmSQL;
SqlDataReader drSQL;
ConnString = "Server=localhost;" + "DataBase=BearScan;" + "Integrated Security=SSPI;Connect Timeout=5";
cnSQL = new SqlConnection(ConnString);
cnSQL = new SqlConnection(ConnString);
cnSQL.Open();
strsql = "INSERT INTO T_ENT_Entries (ENT_Date) VALUES (CONVERT(DATETIME, '" + DateTime.Today + "', 102))";
cmSQL = new SqlCommand(strsql, cnSQL);
drSQL = cmSQL.ExecuteReader();
There is nothing wrong with the connection or DB as this works
//strsql = "INSERT INTO T_ENT_Entries (ENT_Date, ENT_ScanCode) VALUES (CONVERT(DATETIME, '2006-12-12 00:00:00', 102), 'eew')";
The formatting DateTime.Today is “dd/mm/yyyy” although I don’t think that should matter, should it!
Thanks for any suggestions
The code it s something wrong with strsql
int insertResult;
string ConnString;
string strsql;
SqlConnection cnSQL;
SqlCommand cmSQL;
SqlDataReader drSQL;
ConnString = "Server=localhost;" + "DataBase=BearScan;" + "Integrated Security=SSPI;Connect Timeout=5";
cnSQL = new SqlConnection(ConnString);
cnSQL = new SqlConnection(ConnString);
cnSQL.Open();
strsql = "INSERT INTO T_ENT_Entries (ENT_Date) VALUES (CONVERT(DATETIME, '" + DateTime.Today + "', 102))";
cmSQL = new SqlCommand(strsql, cnSQL);
drSQL = cmSQL.ExecuteReader();
There is nothing wrong with the connection or DB as this works
//strsql = "INSERT INTO T_ENT_Entries (ENT_Date, ENT_ScanCode) VALUES (CONVERT(DATETIME, '2006-12-12 00:00:00', 102), 'eew')";
The formatting DateTime.Today is “dd/mm/yyyy” although I don’t think that should matter, should it!
Thanks for any suggestions