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
            {
                
            }
        }

 

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