我用下面的示例代碼,並希望得到一個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