zoukankan      html  css  js  c++  java
  • C# Sqlite For WP7

    C# sqite for wp7
    源:http://code.google.com/p/csharp-sqlite/downloads/list



    部分代码示例:
     

    IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

    isf.DeleteFile("test.db");

    using (SqliteConnection conn = new SqliteConnection("Version=3,uri=file:test.db"))

    {

    conn.Open();

    using (SqliteCommand cmd = conn.CreateCommand())

    {

    cmd.CommandText = "CREATE TABLE test ( [id] INTEGER PRIMARY KEY, [col] INTEGER UNIQUE, [col2] INTEGER, [col3] REAL, [col4] TEXT, [col5] BLOB)";

    cmd.ExecuteNonQuery();

    cmd.Transaction = conn.BeginTransaction();

    cmd.CommandText = "INSERT INTO test(col, col2, col3, col4, col5) VALUES(@col, @col2, @col3, @col4, @col5);SELECT last_insert_rowid();";

    cmd.Parameters.Add("@col", null);

    cmd.Parameters.Add("@col2", null);

    cmd.Parameters.Add("@col3", null);

    cmd.Parameters.Add("@col4", null);

    cmd.Parameters.Add("@col5", null);

    DateTime start = DateTime.Now;

    this.lstResult.Items.Add("Inserting 100 Rows with transaction");

    for (int i = 0; i < 100; i++)

    {

    cmd.Parameters["@col"].Value = i;

    cmd.Parameters["@col2"].Value = i;

    cmd.Parameters["@col3"].Value = i * 0.515;

    cmd.Parameters["@col4"].Value = "สวัสดี な. あ · か · さ · た · な · は · ま · や · ら · わ. 形容詞 hello " + i;

    cmd.Parameters["@col5"].Value = Encoding.UTF8.GetBytes("สวัสดี");

    object s = cmd.ExecuteScalar();

    }

    cmd.Transaction.Commit();

    cmd.Transaction = null;

    this.lstResult.Items.Add("Time taken :" + DateTime.Now.Subtract( start ).TotalMilliseconds + " ms.");

    cmd.CommandText = "SELECT * FROM test";

    using (SqliteDataReader reader = cmd.ExecuteReader())

    {

    while (reader.Read())

    {

    var bytes = (byte[])reader.GetValue(5);

    this.lstResult.Items.Add(string.Format("{0},{1},{2},{3},{4}, {5}",

    reader.GetInt32(0),

    reader.GetInt32(1),

    reader.GetInt32(2),

    reader.GetDouble(3),

    reader.GetString(4),

    Encoding.UTF8.GetString(bytes, 0, bytes.Length)));

    }

    }

    conn.Close();

    }

    }

  • 相关阅读:
    一文搞懂字符集
    机器视觉之eVision
    PID调节
    激光切割质量主要影响因素
    155. 最小栈
    111.二叉树最小深度
    110. 平衡二叉树
    108.将有序数组转换为二叉搜索树
    107. 二叉树的层次遍历 II
    104. 二叉树的最大深度
  • 原文地址:https://www.cnblogs.com/08shiyan/p/2295236.html
Copyright © 2011-2022 走看看