Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading SQLite table information in C#.NET

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?

like image 342
Omkar Avatar asked Jan 22 '11 21:01

Omkar


People also ask

How do I get table information in 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.

Is SQLite written in C?

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.


1 Answers

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:

  • MetaDataCollections
  • DataSourceInformation
  • DataTypes
  • ReservedWords
  • Catalogs
  • Columns
  • Indexes
  • IndexColumns
  • Tables
  • Views
  • ViewColumns
  • ForeignKeys
  • Triggers
like image 70
Thomas Levesque Avatar answered Oct 16 '22 21:10

Thomas Levesque