sbkeenan
11 years agoFrequent Contributor
Retrieving date fields from MySQL database
Hi
I have the following code snippet that I am using to interrogate the underlying MySQL database for our application:
.
.
.
connection = ADO.CreateConnection();
connection.ConnectionString = <my connection string here>;
connection.Open();
cmd = ADO.CreateCommand();
cmd.ActiveConnection = connection;
cmd.CommandText = "SELECT d.description, h.open_time, h.close_time " +
"FROM central.department_opening_hours h " +
"INNER JOIN central.department d " +
"ON d.code = h.department_id " +
"WHERE d.description = '" + aDepartment + "' " +
"AND h.day = '7';";
cmd.CommandType = adCmdText;
rs = cmd.Execute();
var time;
if (rs.recordCount == 1)
{
time = rs("close_time").value;
}
.
.
.
return time;
If I assign any text field or any datetime field that has a null value to the 'time' variable, it works perfectly, but when I attempt to obtain the value of a datetime field that holds the value '0001-01-01 00:00:00', I get the error 'Multiple-step operation generates errors. Check each status value.' and the 'time' variable remains as undefined.
I would be grateful if anyone could shed any light on this - I've had a pretty wasted afternoon because of it!!
Many thanks.
Regards
Stephen.