首先,我正在使用autosuggest框开发数据库。我用DB Browser和导入的数据创建了一个数据库。我正在阅读C#中的文档如何连接数据库和检索数据。问题是出现异常错误:
我已将属性中的数据库与内容选项相关联。我粘贴代码:
Public NotInheritable Class METARTAF
Inherits Page
Dim dbpath As String = Path.Combine(ApplicationData.Current.LocalFolder.Path, "airportsdb.sqlite3")
Dim conn As SQLite.Net.SQLiteConnection = New SQLite.Net.SQLiteConnection(New WinRT.SQLitePlatformWinRT(), dbpath)
Dim airportinfo As List(Of String) = Nothing
Public Sub New()
' This call is required by the designer.
InitializeComponent()
End Sub
Private Sub AutoSuggestBox_TextChanged(sender As AutoSuggestBox, args As AutoSuggestBoxTextChangedEventArgs)
Dim datairport As New List(Of String)
Dim retrieve = conn.Table(Of flugzeuginfo)().ToList
If args.Reason = AutoSuggestionBoxTextChangeReason.UserInput Then
If sender.Text.Length > 1 Then
For Each item In retrieve
datairport.Add(item.IATA)
datairport.Add(item.ICAO)
datairport.Add(item.Location)
datairport.Add(item.Airport)
datairport.Add(item.Country)
Next
airportinfo = datairport.Where(Function(x) x.StartsWith(sender.Text)).ToList()
sender.ItemsSource = airportinfo
End If
Else
sender.ItemsSource = "No results..."
End If
End Sub
Private Sub AutoSuggestBox_SuggestionChosen(sender As AutoSuggestBox, args As AutoSuggestBoxSuggestionChosenEventArgs)
Dim selectedItem = args.SelectedItem.ToString()
sender.Text = selectedItem
End Sub
Private Sub AutoSuggestBox_QuerySubmitted(sender As AutoSuggestBox, args As AutoSuggestBoxQuerySubmittedEventArgs)
If args.ChosenSuggestion Is Nothing Then
stationidtxt.Text = args.ChosenSuggestion.ToString
End If
End Sub
任何人都可以帮忙解决这个问题吗?
答案 0 :(得分:1)
在查询或插入表格之前,您应该CREATE
它。这告诉SQLite你有哪些列并建议数据类型(在其他rdbms上你得到实际的数据类型强制,但SQLite不这样做)。如果这是您的问题,您将需要花费一些时间在SQLite文档上的数据类型以及将它们挂钩到您的应用程序中的能力。
另一方面,当你似乎试图检索数据时,这两个问题之一是错误的。您要么关心连接到错误的数据库(在这种情况下,SQLite通常会为您创建一个空数据库!)或者您指定了错误的表。