-
March 28th, 2011, 12:28 PM
#1
[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.
-
March 28th, 2011, 05:36 PM
#2
Re: SQLite Listing Tables
try this query:
[code]
SELECT name FROM sqlite_master
WHERE type='table'
ORDER BY name;
[code]
-
March 28th, 2011, 05:53 PM
#3
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
}
-
March 31st, 2011, 05:51 AM
#4
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.
-
May 30th, 2013, 02:59 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|