对于学校作业,我需要根据他们的 MAC 地址命名计算机。我有一个带有两列 Mac-Adress 和 Computername 的 mySQL 表。我想通过以下代码使用计算机的mac地址,该代码有效。
全局声明
公共 connStr As String = "Database=Mac;" &_“数据源=本地主机;” & _ "User Id=root;Password=" Public mac_adress As String
获取 Mac 地址
Public Sub MacAdres() Dim nic As NetworkInterface = Nothing
For Each nic In NetworkInterface.GetAllNetworkInterfaces mac_adress = nic.GetPhysicalAddress.ToString Next End Sub
但是,当我想创建 WHERE 语句时,出现错误。我将以下代码用于 WHERE 语句。
Public Sub retriveData() Try Dim query As String = "SELECT * FROM 'mactable' WHERE 'Mac-adres' = '" & mac_adress & "'" Dim connection As New MySqlConnection(connStr) Dim cmd As New MySqlCommand(query, connection) connection.Open() Dim reader As MySqlDataReader reader = cmd.ExecuteReader() While reader.Read() MessageBox.Show(reader.GetString(1)) End While reader.Close() connection.Close() Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub
我究竟做错了什么?
“MySql.Data.MySqlClient.MySqlException”类型的第一次机会异常发生在 >MySql.Data.dll