Conversion failed when converting date and/or time from character string while inserting datetime

后端 未结 15 1300
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 09:34

I was trying to create a table as follows,

create table table1(date1 datetime,date2 datetime);

First I tried inserting values as below,

15条回答
  •  隐瞒了意图╮
    2020-11-22 09:57

    Please Try this.

    SQL Server expects dates in MM/DD/YYYY format,If English is set as your default language.Here am saving datepicker value to sql2008 database.My field type is datetime in database.dpdob is my datepicker name.

               Dim test = dpdob.Text.Replace("-", "/")
               Dim parts As String() = test.Split(New Char() {"/"c})
               Dim firstPart As String = parts(0)
               Dim thirdPart As String = parts(2)
               Dim secondPart As String = parts(1)
               Dim test1 = secondPart + "/" + firstPart + "/" + thirdPart
               Dim dob = test1
    

    Now use dob in your insert query.

提交回复
热议问题