0

Hi, i'm using .Net framework 1.0 & MS Access 2003 database. Using ODBC connection, I want to list all tables in ms access database in a listbox....Please help me.... very urgent...

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sknake
0

Here is an example in C#

private void SetTableList(string factoryName)
    {
      try
      {
        DbProviderFactory factory = DbProviderFactories.GetFactory(factoryName);

        using (DbConnection connection =
                    factory.CreateConnection())
        {
          connection.ConnectionString = _conn.ConnectionString;
          connection.Open();
          _dtTables = connection.GetSchema("Tables");
          _dtColumns = connection.GetSchema("Columns");

          List<string> Sql = new List<string>();
          for (int i1 = 0; i1 < _dtTables.Rows.Count; i1++)
          {
            string tableName = (string)_dtTables.Rows[i1]["TABLE_NAME"];

            try
            {
              string tableType = (string)_dtTables.Rows[i1]["TABLE_TYPE"];
              if ((tableType.ToLower().Contains("system")) || (tableType.ToLower().Equals("access table")))
                continue;
            }
            catch { }

            Sql.Add(tableName);
          }

          Sql.Sort();

          listBoxControlTables.Items.BeginUpdate();
          listBoxControlTables.Items.Clear();

          for (int i1 = 0; i1 < Sql.Count; i1++)
          {
            listBoxControlTables.Items.Add(Sql[i1]);
          }
          listBoxControlTables.Items.EndUpdate();
        }

        if (listBoxControlTables.Items.Count > 0)
          listBoxControlTables.SelectedIndex = 0;
      }
      catch { }
    }

Calling it:

SetTableList(@"System.Data.Odbc");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.