Hi,
How u make that all your table come in a combobox and you can select your table and then the data from that table loads into the datagrid and u can change it...
Printable View
Hi,
How u make that all your table come in a combobox and you can select your table and then the data from that table loads into the datagrid and u can change it...
That would depend on the backend database. They all store the metadata in different areas for you to find.
As Gary mentioned, what database are you using?
an ms access
Thos enames work in SQL Server and I think they're the same in Access. If not you can just do little testing to get the right collection and column names.vb.net Code:
Dim table As DataTable Using connection As New OleDbConnection("connection string here") connection.Open() table = connection.GetSchema("TABLES") End Using myComboBox.DisplayMember = "TABLE_NAME" myComboBox.DataSource = table
well this doesnt set the databases automatic in the combo list if i see good
This code will load the combo box with the names of the data tables and not the schema tables such as MSysAccessObjects, MSysACEs, MSysObjects, MSysQueries and MSysRelationships if that is what you are looking for from an Access data base.
vb Code:
Private Sub btnLoadComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadComboBox1.Click ' Returns schema information for the data source (Data Base) Dim restrictions() As String = {Nothing, Nothing, Nothing, "TABLE"} Dim table As DataTable Using connection As New OleDbConnection("connection string") connection.Open() table = connection.GetSchema("TABLES", restrictions) End Using For Each dr As DataRow In table.Rows Me.cboLoadComboBox1.Items.Add(dr("TABLE_NAME")) Me.cboLoadComboBox1.SelectedIndex = 0 Me.cboLoadComboBox1.Sorted = True Next End Sub
Please do not post duplicate threads.
Dup Thread Deleted
What does not work??? You have to be more specific.
Add a new form to a project
Add a combo box to the form and call it cboLoadComboBox1
Add a button to the form and call it btnLoadComboBox1
In design view double click on the button and copy and past this part of the code into the button click event
vb Code:
' Returns schema information for the data source (Data Base) Dim restrictions() As String = {Nothing, Nothing, Nothing, "TABLE"} Dim table As DataTable Using connection As New OleDbConnection("connection string") connection.Open() table = connection.GetSchema("TABLES", restrictions) End Using For Each dr As DataRow In table.Rows Me.cboLoadComboBox1.Items.Add(dr("TABLE_NAME")) Me.cboLoadComboBox1.SelectedIndex = 0 Me.cboLoadComboBox1.Sorted = True Next
don't forget to add your connection string and it will load the name of the tables in the database.