I次のコード例を使用し、何らかの方法でsqlite3のデータベースのカラム名を取得したい:SQLiteのPRAGMAのtable_info(テーブル)列名を返す(C#でData.SQLiteを使用して)いない
using System;
using System.Data.SQLite;
namespace Program
{
class Program
{
static void Main(string[] args)
{
Program stuff = new Program();
stuff.DoStuff();
Console.Read();
}
private void DoStuff()
{
SQLiteConnection.CreateFile("Database.sqlite");
SQLiteConnection con = new SQLiteConnection("Data Source=Database.sqlite;Version=3;");
con.Open();
string sql = "create table 'member' ('account_id' text not null unique, 'account_name' text not null);";
SQLiteCommand command = new SQLiteCommand(sql, con);
command.ExecuteNonQuery();
sql = "insert into member ('account_id', 'account_name') values ('0', '1');";
command = new SQLiteCommand(sql, con);
sql = "PRAGMA table_info('member');";
command = new SQLiteCommand(sql, con);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetName(0));
}
con.Close();
}
}
}
I私はだから、列名が必要です ..私はしかし、実際のカラム名を取得いけない 「CID名前タイプにnotnull dflt_value PK」 :また、私が得る唯一の結果は次の出力である
for(int i=0;i<reader.FieldCount;i++)
{
Console.WriteLine(reader.GetName(i));
}
var columns = Enumerable.Range(0, reader.FieldCount).Select(reader.GetName).ToList();
を試してみました新しい列をtに書き込む私はアクセスしていない別のサーバーからのAPIの結果に応じて、彼はデータベースを取得します。データを印刷するときには、正しい列名が表示されていることを確認する必要があります。
私はSystem.Data.SQLite 1.0.103を使用しています(ちょうどあなたが知りたい場合にのみ) – Ben