zoukankan      html  css  js  c++  java
  • C#

    1.使用 NuGet 安装 System.Data.SQLite

    2.在 App.config 中配置连接字符串

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    ...
      <connectionStrings>
         <add name="SQLiteDbContext" connectionString="Data Source=MyDatabase.sqlite" providerName="System.Data.SQLite.EF6" />
      </connectionStrings>
    </configuration>

    3.简单使用

    // create
    SQLiteConnection.CreateFile("MyDatabase.sqlite");
    
    SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite");
    m_dbConnection.Open();
    
    string sql = "create table highscores (name varchar(20), score int)";
    
    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
    command.ExecuteNonQuery();
    
    sql = "insert into highscores (name, score) values ('Me', 9001)";
    
    command = new SQLiteCommand(sql, m_dbConnection);
    command.ExecuteNonQuery();// read
    SQLiteCommand sqlCom = new SQLiteCommand("Select * From highscores", m_dbConnection);
    
    SQLiteDataReader sqlDataReader = sqlCom.ExecuteReader();
    
    int i = 1;
    while (sqlDataReader.Read())
    {
        listBox1.Items.Add(i);
        listBox1.Items.Add(sqlDataReader.GetValue(0));
        listBox1.Items.Add(sqlDataReader.GetValue(1));
        i++;
    }
    
    m_dbConnection.Close();
  • 相关阅读:
    [AGC020E] Encoding Subsets
    [Topcoder16346]TwoPerLine
    CF913E Logical Expression
    英语面试
    CRM
    WEB使用第三方支付服务大致流程
    OO语言 prototype 初级用法
    flash设置字体
    air 提示问题
    c#里的BYTE
  • 原文地址:https://www.cnblogs.com/jizhiqiliao/p/10097839.html
Copyright © 2011-2022 走看看