我想用下面的代碼插入到一個數據庫中插入日期時間到SQL Server CE數據庫,但是,每次我得到一個錯誤:通過VB.NET
There was a syntax error in the date format. [ Expression = @DOB ]
我都試過,幾乎每一個日期格式可用,tolongdate,toshortdate等&無論我使用這個錯誤顯示。
數據庫列格式爲datetime
。任何想法,我錯了?
代碼:
' Insert New User - Create Connection
Dim sqlConn As New SqlCeConnection(My.Settings.CompDbConnectionString)
' Open Connection
sqlConn.Open()
' Query DB
Dim sqlComm As New SqlCeCommand("INSERT INTO Profiles(Title, FirstName, LastName, DOB) VALUES(@Title, '@FirstName', '@LastName', '@DOB')", sqlConn)
' Add Parameters
sqlComm.Parameters.Add(New SqlCeParameter("@Title", SqlDbType.NVarChar)).Value = ComboTitle.SelectedItem.ToString()
sqlComm.Parameters.Add(New SqlCeParameter("@FirstName", SqlDbType.NVarChar)).Value = txtFirstName.Text
sqlComm.Parameters.Add(New SqlCeParameter("@LastName", SqlDbType.NVarChar)).Value = txtLastName.Text
sqlComm.Parameters.Add(New SqlCeParameter("@DOB", SqlDbType.DateTime)).Value = DteDOB.Value.ToUniversalTime
' Insert Into Database
Try
sqlComm.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Failed To Update Your Details:" & vbCrLf & ex.Message)
Exit Sub
End Try
' Close Connection
sqlConn.Close()
在此代碼中,VALUES(@Title,'@ FirstName','@LastName','@DOB')'嘗試刪除撇號 – tcarvin 2012-07-12 18:44:24