C#sqlite

 2020年3月12日13:40:27

先記錄下,到時再封裝

using System.Data.SQLite;

//使用sql查詢語句,並顯示結果

void SqLite_query()
        {

            try
            {

                SQLiteConnection conn = null;

                string dbPath = "Data Source =" + Environment.CurrentDirectory + "/test.db";
                conn = new SQLiteConnection(dbPath);//創建數據庫實例,指定文件位置
                conn.Open();//打開數據庫,若文件不存在會自動創建

                string sql = "select * from student order by id asc ";

                SQLiteCommand command = new SQLiteCommand(sql, conn);
                SQLiteDataReader reader = command.ExecuteReader();

                Console.WriteLine(reader.FieldCount);

                // reader.Close();
                while (reader.Read())
                    Console.WriteLine("Name: " + reader["name"] + "\tid " + reader["id"]);
                Console.ReadLine();

            }
            catch
            {
                
            }
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章