[RESOLVED] SQLite Listing Tables
For some reason , the answer to this complete eludes me.:confused:
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
Re: SQLite Listing Tables
try this query:
[code]
SELECT name FROM sqlite_master
WHERE type='table'
ORDER BY name;
[code]
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
}
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!:D
Re: [RESOLVED] SQLite Listing Tables
:wave: 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;
}