I have a listbox and a datagrid.
When the form is loaded the listbox is filled with a list of tables from a selected database (SQL 2008).
sqlstr = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME"
Then I have a SelectedIndexChanged that populates the datagrid with the contents of the selected table.
Dim ConnString As String = mySQLconn
Dim ds As DataSet
Dim dv As DataView
Try
Dim SQLConn As New SqlConnection(ConnString) 'The SQL Connection
ds = New DataSet
dv = New DataView
Dim ad As New SqlDataAdapter("SELECT * FROM " + lbListAllTables.SelectedItem, SQLConn)
ad.Fill(ds, "SelectedTable")
dv.Table = ds.Tables("SelectedTable")
Me.DataGridView1.DataSource = dv
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
This works just fine if the table name is one word (clients) but if it two words (setup client) I get a 'Incorrect syntax near the keyword 'setup'' error.