我正在尝试在 WinRT 8.1 中使用日期和时间选择器控件,如图所示:
日期选择器控件
时间选择器控制:
现在在我的表中声明它们,如图所示:
Public Class mydata
<MaxLength(5), PrimaryKey> _
Public Property name() As String
<MaxLength(50)> _
Public Property date1() As DateTime
<MaxLength(50)> _
Public Property date2() As DateTime
End Class
现在我正在尝试使用它们,如图所示:
Dim dateFormatter As New DateTimeFormatter("shortdate")
Dim timeFormatter As New DateTimeFormatter("shorttime")
Dim selectedDate1 As DateTimeOffset = Me.selectedDate1.Date
Dim combinedate1Value As New DateTimeOffset(New Date(selectedDate1.Year, selectedDate1.Month, selectedDate1.Day) + Me.selectedDate1.Time)
Dim selectedDate2 As DateTimeOffset = Me.selectedDate2.Date
Dim combineddate2Value As New DateTimeOffset(New Date(selectedDate2.Year, selectedDate2.Month, selectedDate2.Day) + Me.selectedDate2.Time)
If CustomerName.Text <> "" Then
Dim dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "mydata.db")
Using db = New SQLite.SQLiteConnection(dbpath)
' Create the tables if they don't exist
db.Insert(New person() With {.name = CustomerName.Text.ToString(), .date1 = dateFormatter.Format(combinedate1Value) & " " & timeFormatter.Format(combinedate1Value), .date2= dateFormatter.Format(combinedate2Value) & " " & timeFormatter.Format(combinedate2Value)})
db.Commit()
db.Dispose()
db.Close()
Dim line = New MessageDialog("Records Inserted")
Await line.ShowAsync()
End Using
Else
Throw New NullReferenceException("Please enter the required fields")
End If
现在的问题是在保存时出现异常,如图所示:
因此,任何人都让我知道如何使用正确的数据类型将日期保存到我的表中。