-
SQL query by Datetime
I have a table in my SQL Server DB that contains a DateTime type field set up as the Primary Key. I have the following code that performs a search:
Code:
string SQL = "SELECT * FROM [MyEventLog] Where [theDate] = '13/03/2004 08:22:37';
SqlCommand sqlComm = new SqlCommand(SQL,sqlConn);
SqlDataReader sqlReader = sqlComm.ExecuteReader();
while(sqlReader.Read())
{
richNote.Text = sqlReader["theNote"].ToString();
}
There is definately a record that contains the date and time mentioned above, but my sql cannot find it. Do i need to convert something or change the sql query structure?
anyone?
thanks
-
I don't see a AM or PM in the date time.
Check your SQL table again and see if the value contains that part....I think it does.
-
If you haven't made any changes to how sql server stores datetime fields, it'll be stored like this:
Code:
2004-03-13 09:05:48.157
...note the trailing .157. There might be some change on the end of it.
-
Just curious. Why would you use a date as a primary key?