DataGridView1.DataSource = Nothing
Dim con As New MySqlConnection("Data Source=localhost;user id=root; password=; database=ugibl;")
Dim da As MySqlDataAdapter = Nothing
Dim dt As New DataTable
Dim SQL As String = ""
Try
**SQL = "select * FROM duty where '" & ComboBox3.Text & "' = '" & TextBox15.Text & "' "**
con.Open()
da = New MySqlDataAdapter(SQL, con)
da.Fill(dt)
con.Close()
DataGridView1.DataSource = dt
Catch ex As Exception
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Subere
答案 0 :(得分:0)
在列名称周围的MySql中使用的字符是反引号( ALT + 096 )而不是单引号。所以你创建sql命令的行是错误的。
SQL = "select * FROM duty where `" & ComboBox3.Text & "` = ....
但请记住,您不应该使用参数来构建连接字符串的sql命令。在您的情况下,该参数应该用于表示where语句中的值
...
SQL = "select * FROM duty where `" & ComboBox3.Text & "` = @param1"
con.Open()
da = New MySqlDataAdapter(SQL, con)
da.SelectCommand.Parameters.Add("@param1", MySqlDbType.VarChar).Value = TextBox15.Text
da.Fill(dt)
....
请注意,您不能将参数用于列名称,只能将它们用于值