I would like to read the table and column information in C#.NET Windows application. I know that there is SMO base access for SQL Server. On similar ground is there any API for SQLite?
If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.
SQLite is written in ANSI-C. The C programming language is used because it is the universal assembly language - it can run on just about any hardware and on just about any operating system. No matter what programming language is used for the application code, it can usually interface easily with a library written in C.
You can use the GetSchema
method :
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SQLite");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = @"Data Source=D:\tmp\test.db";
connection.Open();
DataTable tables = connection.GetSchema("Tables");
DataTable columns = connection.GetSchema("Columns");
tables.Dump();
columns.Dump();
}
GetSchema
returns a DataTable that contains information about the tables, columns, or whatever you specify. Valid GetSchema
arguments for SQLite include:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With