在优酷"VB.NET - How to create an SQLite database within Visual Studio"上找到。当我从工作室运行它时.不起作用



我一直无法发布另一个使用DB Browser创建的数据库的应用程序:每次我发布并移动到另一台电脑时,它都无法打开数据库,所以我想尝试不同的方法。

这是在模块1中,注意我把子名称改为myMain,因为它一直告诉我我的项目有太多Mains,不知道为什么,因为这是唯一引用的地方:

我引用的视频链接是:https://video.search.yahoo.com/search/video?fr=mcafee&p=VB.NET+-+How+to+create+an+SQLite+数据库+within+VisualStudio#id=1&vid=51539dac133b92e6a3510d3cbbcdeba8&action=点击

Sub myMain()
Dim Server As New Server()
Server.createDataBase()
Server.insertUsername("Paul Higginbotham")
Console.ReadKey()
End Sub

这是在公共服务器类中:

'Where to install the database in this case on the desktop
Dim location As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
'Name the database
Dim fileName As String = "myDataBase.db"
'Combine the files together
Dim fullPath As String = System.IO.Path.Combine(location, fileName)
'Create a public connection so you don't have to keep making the connection
'everytime you are querying the database
Public connectionString As String = String.Format("Data Source = {0}", fullPath)
'Create the DataBase
Public Sub createDataBase()
If Not duplicateDataBase(fullPath) Then
Dim createTable As String = "CREATE TABLE 'userLoginTable' (
'id'    INTEGER,
'username'  TEXT,
PRIMARY KEY('id' AUTOINCREMENT)
);"
Using SqlConn As New SQLiteConnection(connectionString)
Dim cmd As New SQLiteCommand(createTable, SqlConn)
SqlConn.Open()
cmd.ExecuteNonQuery()
End Using
End If

在视频中创建了一个控制台应用程序。由于收到过多Sub Main的警告,我相信您是在Windows窗体应用程序中尝试此代码。没有任何东西在调用myMainsub。请在控制台应用程序中尝试代码,并将sub的名称保留为SubMain。将类同样添加到控制台应用程序中。不要忘记添加Nuget包和Imports语句。

您也可以将其保留为Windows窗体,并将myMain中的代码放入Form.Load或添加到窗体中的Button事件中。类保持不变。

相关内容

最新更新