我在窗體上使用DatePicker和textfield來選擇日期,默認情況下它會在文本字段中顯示爲dd/mm/yyyy。因此,當我編寫我的代碼時,我使用這種格式來保持一致。但是當我保存一個像03/10/2015(這是十月的第三天)的日期時,它將被保存爲3月10日。鑑於下面的代碼,我需要改變什麼才能正確保存到數據庫?將日期和月份保存到數據庫時反轉
Private Sub cmdSave_Click()
...
Dim StartDate As String
Dim EndDate As String
Dim SDate As Date
Dim EDate As Date
...
StartDate = Me.txtStartDate.Value & " " & Me.txtStartTime.Value
EndDate = Me.txtEndDate.Value & " " & Me.txtEndTime.Value
SDate = CDate(Format(StartDate, "dd\/mm\/yyyy hh:mm"))
EDate = CDate(Format(EndDate, "dd\/mm\/yyyy hh:mm"))
If Me.txtOtherDetails.Value = "" Then
query1 = "INSERT INTO Shifts (Schedule_ID,Start_Date_Time,End_Date_Time,Location)" & _
" VALUES (" & ScheduleID & ",#" & SDate & "#,#" & EDate & "#," & LocationID & ")"
Else
query1 = "INSERT INTO Shifts (Schedule_ID,Start_Date_Time,End_Date_Time,Location,Other_Details)" & _
" VALUES (" & ScheduleID & ",#" & SDate & "#,#" & EDate & "#," & LocationID & ",'" & Me.txtOtherDetails.Value & "')"
End If
'Debug.Print query1
ShiftID = ExecuteInsert(query1)
End Sub
你的建議的工作。謝謝。 – Alan