c#操作sqlite

一、添加选中dll引用如下图

二、下载一个sqlite建表建库工具sqlitedatabasebrowser如下图

三、使用sqlitedatabasebrowser建库建表

四、插入表数据如下图

四、连接sqlite

public SQLiteConnection GetCon()
        {
    readonly  string DbFile=@"F:\project\net_mk_web\zkx_mk_web\zkx_mk_web\bin\text.db";
    SQLiteConnection SQLCON = new SQLiteConnection("Data Source=" + DbFile + ";Version=3");
            return SQLCON;
        }

 

 public SQLiteConnection open()
        {
            //SQLiteConnection.CreateFile(DbFile);
            SQLiteConnection sqlcon = GetCon();
            if(sqlcon.State!=ConnectionState.Open)
            {
                sqlcon.Open();
            }
            return sqlcon;
        }

五、执行sqlite

  public List<String> Execution()
        {
            List<string> data = new List<string>();
            SQLiteConnection opencon = open();
            using (SQLiteCommand sqlcommand = new SQLiteCommand("select * from user", opencon))
            {
                SQLiteDataReader sqlread = sqlcommand.ExecuteReader();
                while (sqlread.Read())
                {
                    data.Add(sqlread["username"].ToString());
                }
            }
            return data;
        }

 

 

posted @ 2014-01-08 17:40  srfree  阅读(368)  评论(0编辑  收藏  举报