我是VB .net的新手并且正在使用SQLite。我无法访问Test1.db3,下面的代码只是创建一个新文件Test1.db3,因此当我去阅读文件时,我收到一个回复,说“用户”表不存在。我正在使用VS Express 2013。
Sub Main()
Dim Path As String = "J:\Location\SQLITE\"
Dim dataBase As String = "test1.db"
Dim cs As String = Path & dataBase
Dim myConnection As New SQLiteConnection()
Dim cadeomSQL As String = "Data Source=" & cs & ";"
myConnection.ConnectionString = cadeomSQL
myConnection.Open()
Dim sSQL As String = "SELECT * FROM Users"
Using cmd As New SQLiteCommand(sSQL, myConnection)
Dim rdr As SQLiteDataReader = cmd.ExecuteReader()
Using rdr
While (rdr.Read())
Console.WriteLine(rdr.GetString(0) & rdr.GetString(1) & rdr.GetString(2))
End While
End Using
End Using
myConnection.Close()
End Sub
任何建议都将不胜感激
答案 0 :(得分:0)
尝试一下!
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dataBase As String = "test1.db"
Dim Path As String = $"J:\Location\SQLITE\{dataBase}"
Dim cadeomSQL As String = $"Data Source={Path};Version=3;New=False;Compress=True;"
Dim myConnection As New SQLiteConnection()
myConnection.ConnectionString = cadeomSQL
myConnection.Open()
Dim sSQL As String = "SELECT * FROM Users"
Using cmd As New SQLiteCommand(sSQL, myConnection)
Dim rdr As SQLiteDataReader = cmd.ExecuteReader()
Using rdr
While (rdr.Read())
Console.WriteLine($"{rdr.Item(0)} {rdr.Item(1)} {rdr.Item(2)} {vbNewLine}")
End While
End Using
End Using
myConnection.Close()
End Sub