Hi this code is to fill up my Combo1 Item which is came from my Table1

        .Combo_Main_AM.Items.Clear()
        Dim da As New OleDbDataAdapter("Select * from Table1", con)
        da.Fill(dt)
        For Each myRow In dt.Rows
            .Combo1.Items.Add(myRow.Item(0))
        Next

so it will add up the combo1

Jessie
James
Nick

now the question is how can i get the that name to be used in my query?
using loop?
i will use it to be the name of my table i want to search.

da.fill(dt)
Dim da As New OleDbDataAdapter("Select * from dt", con)
    'Code here
Next

I hope you understand what i mean.

now the question is how can i get the that name to be used in my query?
using loop?
i will use it to be the name of my table i want to search.

I hope you understand what i mean.

Nope!, I do not understand.

Do you mean that you want to retrieve a list of Table names from the DB and be able to substitute the Table name in the query?

This example is for a SQLClient connection, but should work for OleDb as well.

   Dim cn As New SqlClient.SqlConnection(My.Settings.NorthwindConnectionString)
   cn.Open()
   For Each r As DataRow In cn.GetSchema("Tables").Rows
      ' Note that this will pull both Tables &" Views.  You may need to filter out the Views.
      Dim TableName As String = r("Table_Name").ToString
      ' do something with TableName
   Next
   cn.Close()

I mean if you look into my Combobox i have loaded into the add items the Views of my Table
which is Jessie, James and Nick.

Now, i dont know how to i can able to put them into my query using loop.

' Note that this will pull both Tables &" Views. You may need to filter out the Views.

How can i filter out the views?

Now i get it many thanks @TnTinMN

    Form_Month_End_Report.ComboBox1.Items.Clear()

    Dim cn As New OleDbConnection
    cn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & ConDashBoard & "';")
    cn.Open()

    For Each R As DataRow In cn.GetSchema("Tables", New String() {Nothing, Nothing, Nothing, "Table"}).Rows

        Form_Month_End_Report.ComboBox1.Items.Add(R.Item(2).ToString)
    Next

    'and then i will put my query in here so it will loop trough the names.

    cn.Close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.