Results 1 to 5 of 5

Thread: How can i do when i insert date to sqlserver it also error?

  1. #1

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Question How can i do when i insert date to sqlserver it also error?

    Hi all!

    i use sqlserver for database and vb.net as interface.
    when i insert datetime to the column that has format datetime it is also error.
    when the datetime format of system is "dd/mm/yyyy hh:mm:ss".
    but if system datetime format is 'mm/dd/yyyy hh:mm:ss' it is not error.
    so what sould i do if i do not to change the system datetime format?
    please Help me?

    best regards,
    thirith.

  2. #2
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: How can i do when i insert date to sqlserver it also error?

    Hi !

    What are you using to update your database ? SQL "INSERT INTO" Statement or DataAdaptor with DataSet ?

  3. #3
    Addicted Member
    Join Date
    Jan 2005
    Location
    Montréal
    Posts
    160

    Re: How can i do when i insert date to sqlserver it also error?

    try to format it this way before putting the date in your sql statement :

    VB Code:
    1. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

    should work whatever regional settings you have.
    There are no stupid questions, but a whole bunch of dumb sayings !

    Save time on database code, try DataLG !

  4. #4

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Resolved Re: How can i do when i insert date to sqlserver it also error?

    Hi !

    thanks when i try to use format as "yyyy-MM-dd HH:mm:ss" before i insert date to sqlserver thruogh INSERT statment.


    OK Bye.
    Thirith

  5. #5
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: How can i do when i insert date to sqlserver it also error?

    Throught SQL Statement i've coem to a problem similar and the fax i've found is to convert de date to a double and reconvert it to date on the SQL Serer side

    Like this:
    VB Code:
    1. strsql = "INSERT INTO tblTable (Id, TheDate, Notes) VALUES (1, Convert(DateTime, " & dtDate.ToOADate - 2 & ", 'The notes...'))"

    In this way, no mater the date format it will work perfecly

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