[RESOLVED] SQLite Listing Tables
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] SQLite Listing Tables

  1. #1
    Join Date
    Mar 2008
    Location
    St. Petersburg, FL
    Posts
    3

    [RESOLVED] SQLite Listing Tables

    For some reason , the answer to this complete eludes me.

    Every example I have found anywhere, assumes that you already know what the table names are.

    Does anyone know a quick and dirty way of listing existing table names in an SQLite database?

    I have been going through the SQLite .NET help.
    The SQLiteMetaDataCollectionNames Fields is really confusing. (they need to include more samples) The most I got it to give back to me was "Tables" on a line all by itself.

    Any help will be deeply appreciated.
    I am using VS2010.
    .NET 3.5
    And the newest version of SQLite. I downloaded it last week.
    Thanks
    Thank you.
    Frank G.

  2. #2
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: SQLite Listing Tables

    try this query:

    [code]
    SELECT name FROM sqlite_master
    WHERE type='table'
    ORDER BY name;
    [code]

  3. #3
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: SQLite Listing Tables

    coded a button to fill a datagrid to get the names of all the tables.

    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                myconnection.Open(); //opens connection 
    
                SQLiteCommand getTables = new SQLiteCommand("Select name From sqlite_master where type='table' order by name;",myconnection);
                SQLiteDataAdapter myCountAdapter = new SQLiteDataAdapter(getTables);
                DataSet myCountDataSet = new DataSet();
                myCountAdapter.Fill(myCountDataSet, "name");
    
                this.dataGrid1.DataSource = myCountDataSet;
                this.dataGrid1.DataMember = "name";
                
                myconnection.Close(); // closes the connection
            }

  4. #4
    Join Date
    Mar 2008
    Location
    St. Petersburg, FL
    Posts
    3

    Re: SQLite Listing Tables

    Thanks Forgottenhart!

    That worked Perfectly.

    I got one of the SQLite system tables with it, but I can filter that out.

    Thanks again!
    Thank you.
    Frank G.

  5. #5
    Join Date
    May 2013
    Posts
    1

    Thumbs up Re: [RESOLVED] SQLite Listing Tables

    public List<string> GetListTables()
    {
    List<string> tables = new List<string>();
    using (SQLiteConnection con = GetConnection())
    {
    con.Open();
    DataTable dt = con.GetSchema("Tables");
    foreach (DataRow row in dt.Rows)
    {
    string tablename = (string)row[2];
    tables.Add(tablename);
    }
    con.Close();
    }
    return tables;
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center