0

I have a method within a class that writes all of the rows and columns from a table in my database. However, when I try to fetch data from myTable in my DB with readAllFromTable("myTable", myDataGridView) it fails because the selected table is wrapped around quotes, so the query looks like this:

SELECT * FROM "mytable"

...When it I need it to look like this:

SELECT * FROM mytable


Source code:

 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
robert
  • 187
  • 2
  • 10

0 Answers0