zoukankan      html  css  js  c++  java
  • CUBRID学习笔记 36 在net中添加多行记录

    using System.Data.Common;
     
    using CUBRID.Data.CUBRIDClient;
     
    namespace Sample
    {
        class Add_MultipleRows
        {
            /* conection string */
            /* Please modify before using. */
            static readonly string _connString = "server=127.0.0.1;database=demodb;port=33000;user=public;password=";
     
            public void using_sql()
            {
                using (CUBRIDConnection conn = new CUBRIDConnection())
                {
                    conn.ConnectionString = Add_MultipleRows._connString;
                    conn.Open();
     
                    string sql = "drop table if exists table11;";
                    try
                    {
                        using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch { }
                     
                    /* create new table */
                    sql = "create table table11(a string , b string, c string);";
                    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
     
                    /* insert multi rows values */
                    sql = "insert into table11 (a, b, c) values ('1', '2','3'),('a', 'b','c'),('!', '@', '#');";
                    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
     
                    /* verify count */
                    sql = "select count(*) from table11";
                    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                    {
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            reader.Read();
                            if (reader.GetInt32(0) == 3)
                                ; // do something;
                        }
                    }
     
                    sql = "drop table11;";
                    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
    }
    

      上面的代码是正常的体位.   

          下面的是批量提交.主要使用了BatchExecuteNoQuery 这个很有情趣的工具

    using System.Data.Common;
     
    using CUBRID.Data.CUBRIDClient;
     
    namespace Sample
    {
        class Add_MultipleRows
        {
            /* conection string */
            /* Please modify before using. */
            static readonly string _connString = "server=127.0.0.1;database=demodb;port=33000;user=public;password=";
     
             public void using_cubrid_connection()
            {
                using (CUBRIDConnection conn = new CUBRIDConnection())
                {
                    conn.ConnectionString = Add_MultipleRows._connString;
                    conn.Open();
     
                    string[] sqls = {
                                        "drop table if exists table11;",
                                        "create table table11(a string , b string, c string);",
                                        "insert into table11 (a, b, c) values ('1', '2','3');",
                                        "insert into table11 (a, b, c) values ('a', 'b','c')",
                                        "insert into table11 (a, b, c) values ('!', '@', '#');"
                                    };
                    conn.BatchExecuteNoQuery(sqls);
                     
                    /* verify count */
                    string sql = "select count(*) from table11";
                    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                    {
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            reader.Read();
                            if (reader.GetInt32(0) == 3)
                                ; // do something;
                        }
                    }
     
                    sql = "drop table11;";
                    using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
    }
    

      

  • 相关阅读:
    广播通信
    IP多播
    套接字选项
    IO处理线程
    单源最短路径
    活动安排问题贪心算法
    贪心算法
    IO控制命令
    [转]qsort详解
    2012下半年学习目录
  • 原文地址:https://www.cnblogs.com/wang2650/p/5288034.html
Copyright © 2011-2022 走看看