Reading SQLite table information in C#.NET

前端 未结 1 1301
囚心锁ツ
囚心锁ツ 2021-01-02 14:20

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

相关标签:
1条回答
  • 2021-01-02 14:50

    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
    0 讨论(0)
提交回复
热议问题