我正在使用MySQL和VB.Net创建小型数据库程序。我使用WampServer for MySQL和MySQL 6.9.8连接器。当我连接到互联网时,所有代码都正常工作,但是当我断开连接时,它显示“未找到数据库”错误。我的数据库本地存储在Wamp phyMyAdmin
中这是我的代码
Try
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = "DATABASE=" & My.Settings.myDB & ";" _
& "SERVER=" & My.Settings.myServer & ";user id=" & My.Settings.myUsername _
& ";password=" & My.Settings.myPassword & ";port=" & _
My.Settings.myPort & ";charset=utf8;Convert Zero Datetime=True"
conn.Open()
End If
Catch myerror As Exception
MessageBox.Show("Error Connecting to the database", "Error Database Server", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End
End Try
这是我的其他代码;
Try
mdlCon.conn.Open()
Dim rd As MySqlDataReader
Dim cmd As New MySqlCommand
Dim dt As New DataTable
cmd.CommandText = "select * from studentdeatil Order by sid DESC"
cmd.Connection = mdlCon.conn
rd = cmd.ExecuteReader
dt.Load(rd)
rd.Close()
For Each rowD As DataRow In dt.Rows
Dim dgvRow As String() = New String() {rowD.Item(3), rowD.Item(1), rowD.Item(2), rowD.Item(4), rowD.Item(5), rowD.Item(6), rowD.Item(7), rowD.Item(8), rowD.Item(9), rowD.Item(10), "", "OLD", rowD.Item(0)}
DataGridView1.Rows.Add(dgvRow)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try