Experts, please help me with code to connect an existing SQL Table to an already EXISTING, programmatically created datagridview. The major challenge for me is how to write line of code for the datagridview when its name is based on the variable "moduletableCB.text"??
For example if you hardcode a datagridview named "dg" you can write the line like this:
dg.datasource = table (this would work if it were my situation)
But in this case the datagridviews were programmatically created indexing off of a variable and the user is selecting the datagridview to populate based on the their selection in the combobox "moduletableCB" so I tried this line of code but it doesn't work because my syntax is out of wack:
moduletableCB.datasource = table (this doesn't work...help!)
SQL table: name comes from variable "moduletableCB.text"
DataGridView: name comes from variable "moduletableCB.text"
The code in the snippet below is my failed attempt...it creates a NEW datagridview on the form instead of what I need which is connecting an EXISTING datagridview to the SQL Table
Dim dbadp As New SqlDataAdapter("USE " & DBName & ";SELECT * FROM " & "dbo." & moduletableCB.Text, Conn2)
Dim dTable As New DataTable
Dim dgv As New DataGridView
dgv.Name = Me.moduletableCB.Text
dgv.Location = New Point(20, 20)
dgv.DataSource = dTable