我在类中有一个方法,它从数据库中的表中写入所有行和列。但是,当我尝试使用readAllFromTable("myTable", myDataGridView)
从我的数据库中的myTable获取数据时,它会失败,因为所选的表包含引号,所以查询如下所示:
SELECT * FROM" mytable"
......当我需要它时:
SELECT * FROM mytable
源代码:
Public Sub readAllFromTable(table As String, datagrid As DataGridView)
Dim sda As New MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
Dim sql As String = "SELECT * FROM @table"
sqlQuery = New MySqlCommand(sql, login.connection)
sqlQuery.Parameters.AddWithValue("@table", table)
sda.SelectCommand = sqlQuery
sda.Fill(dbDataSet)
bSource.DataSource = dbDataSet
datagrid.DataSource = bSource
sda.Update(dbDataSet)
End Sub