I want to run a select command and I’ve a dropdownlist populated with database table names. How to write the select command? Here is my code
Dim da As New OdbcDataAdapter("select table_name from INFORMATION_SCHEMA.tables WHERE TABLE_TYPE = 'BASE TABLE' and table_schema='public'", dbcon.con)
Dim dt As New DataTable
da.Fill(dt)
ddltablename.DataSource = dt
ddltablename.DataTextField = "table_name"
ddltablename.DataValueField = "table_name"
ddltablename.DataBind()
End Sub
Protected Sub btndump_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndump.Click
Dim da As New OdbcDataAdapter("select * from ddltablename.SelectedItem.tostring", dbcon.con)
Dim ds As New DataSet
da.Fill(ds)
End Sub
2
Answers
Probably something like this:
Getting the value of your control,
ddltablename
, has to be done in the application context, not within the SQL command.Sure, lets drop in your combo box, and then a gridview.
like this:
And our code can thus be:
Output:
Or you can say do this: