zoukankan      html  css  js  c++  java
  • Sqlite 快速批量插入数据 测试

     public static int insertDbBatch()
            {
    
    
                string sql = "";
          
            
                SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + dbFile + ";Initial Catalog=sqlite;Integrated Security=True;");
                conn.Open(); 
                SQLiteCommand cmd = new SQLiteCommand(conn);
                DbTransaction trans = conn.BeginTransaction(); // <-------------------
              
                int cnt = 0;
                try
                {
    
                 
    
                    for (int i = 1; i <= 50000; i++)
                    {
    
                       // sql = "insert into members (uid,hashCode,nickName) select '" + rnd.Next(11111111, 999999999) + "','hash" + rnd.Next(11111111, 999999999) + "','测试数据'";
                        sql = "insert into members (uid,hashCode,nickName) select '" + Guid.NewGuid() + "','hash" + rnd.Next(11111111, 999999999) + "','测试数据'";
                        cmd.CommandText = sql;
                        cnt += cmd.ExecuteNonQuery();
    
                    }
    
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // MessageBox.Show(ex.Message);
                }
                finally
                {
    
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
    
    
                }
    
    
                return cnt;
            }
    

      

  • 相关阅读:
    ie678兼容问题
    ie6/7中 zindex兼容问题
    mac svn 操作
    location.hash
    让 div 浮动到底端
    timeout问题
    让footer 自适应在底端
    js获取浏览器的高度
    ajax浏览器后退功能实现
    经典SQL语句大全(二)
  • 原文地址:https://www.cnblogs.com/wgscd/p/9407137.html
Copyright © 2011-2022 走看看