我用下面的示例代码,并希望得到一个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();
}
}
}
我也试过
for(int i=0;i<reader.FieldCount;i++)
{
Console.WriteLine(reader.GetName(i));
}
var columns = Enumerable.Range(0, reader.FieldCount).Select(reader.GetName).ToList();
唯一的结果我得到的是下面的输出: “CID名类型NotNull dflt_value PK” 我不虽然得到实际的列名.. 我需要的列名,因为我给t写新的专栏他的数据库取决于来自另一个服务器的API的结果,我无法访问它。在打印数据时,我想确保显示正确的列名称。
我使用System.Data.SQLite 1.0.103(以防万一你想知道) – Ben