CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Location
    Singapore
    Posts
    9

    C# & SQL Server DateTime formats

    my problem goes likes this:
    whenever a user creates a record (application is coded in C#), the program should automatically insert the current date into the SQL Server DB together with the record. the field for the date in the DB is defined as datetime. However, I have problems coming up with the appropriate c# code to insert the time into the DB. I do not wish to change the data type to string and have the date converted to a string first b4 I store it in the DB. Help is greatly appreciated.

    one other thing. SQL Server would automatically insert the time if I manually keyed in a date in the DB. Is there anyway I can bypass that? I'm not interested in the time at all? Anyway, I'm using SQL Server 7. Would SQL Server 2000 provide a bettter fix for my problem?


  2. #2
    Join Date
    May 2002
    Location
    Atlanta,GA
    Posts
    262

    Re: C# & SQL Server DateTime formats

    Try the System.Data.SqlClient.SqlDataReader. This class has the ability to convert from C# DateTime and SQL Date times. It can also convert I believe any SQL type to any C# type.

    Jared Parsons
    Jared

  3. #3
    Join Date
    May 2002
    Location
    Singapore
    Posts
    9

    Re: C# & SQL Server DateTime formats

    i don't quite get wad u mean. could you elaborate your point further? perhaps you could include some source code.
    thanks


  4. #4
    Join Date
    May 2002
    Location
    Atlanta,GA
    Posts
    262

    Re: C# & SQL Server DateTime formats

    I'm still slightly confused about your first post. ARe you simply trying to convert a C# dateTime into a Sql ready format? If so then this shoudl work.


    public SqlDateTime getDateTime()
    {
    return new SqlDateTime(DateTime.Now);
    }





    Jared Parsons
    Jared

  5. #5
    Join Date
    May 2002
    Location
    Singapore
    Posts
    9

    Re: Re: C# & SQL Server DateTime formats

    Originally posted by jparsons
    I'm still slightly confused about your first post. ARe you simply trying to convert a C# dateTime into a Sql ready format? If so then this shoudl work.


    public SqlDateTime getDateTime()
    {
    return new SqlDateTime(DateTime.Now);
    }





    Jared Parsons
    exactly wad i wanted!
    thx for everything.

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

Featured