Results 1 to 4 of 4

Thread: SQL query by Datetime

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Question 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

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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.

  4. #4
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    Just curious. Why would you use a date as a primary key?
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width