我可以毫无错误地调试我的项目,但是当我构建它并将可执行应用程序复制到另一台计算机时,应用程序根本没有运行。表格甚至没有出现在屏幕上。
(Here)是我的错误的屏幕截图。
这是我的源代码。
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MySQLConnection = New MySqlConnection
Dim Command As New MySqlCommand
Dim MyAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim str_carSql As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim response As Boolean = False
Button1.Enabled = False
Try
response = My.Computer.Network.Ping("www.db4free.net")
Label2.Text = "ONLINE"
Label2.ForeColor = Color.Green
Button1.Enabled = True
Catch ex As Exception
Label2.Text = "OFFLINE"
Label2.ForeColor = Color.Red
MsgBox("No internet connection!", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Cursor = Cursors.WaitCursor
Try
MySQLConnection.ConnectionString = "server=db4free.net ;port=3306; user=prav5ef; password=prav5eF; database=databasetest;"
MySQLConnection.Open()
MsgBox("Connected to server!")
Catch ex As Exception
MsgBox("Failed connecting to server!", MsgBoxStyle.Critical)
End Try
Try
str_carSql = "insert into databasetest (id,name,password) values (@id,@name,@password)"
sqlCommand.Connection = MySQLConnection
sqlCommand.CommandText = str_carSql
sqlCommand.Parameters.AddWithValue("@id", TextBox1.Text)
sqlCommand.Parameters.AddWithValue("@name", TextBox2.Text)
sqlCommand.Parameters.AddWithValue("@password", TextBox3.Text)
sqlCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox("ID existed: Could not insert record")
End Try
MsgBox("Done")
Application.Restart()
End Sub
End Class
以下是应用程序假设显示的内容:
我使用的在线数据库是db4free.net: