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();
                    }
                }
            }
        }
    }
    

      

  • 相关阅读:
    HubSpot – 网站开发必备的 jQuery 信息提示库
    Ink – 帮助你快速创建响应式邮件(Email)的框架
    Simptip – 使用 Sass 制作的 CSS Tooltip 效果
    字体大宝库:12款好看的手写艺术字体免费下载
    『摄影欣赏』20幅温馨浪漫的精美照片欣赏【组图】
    Stickup – 轻松实现元素固定效果的 jQuery 插件
    精品素材:15套免费的 Photoshop 自定义图形集
    Node.js 入门手册:那些最流行的 Web 开发框架
    潮流设计:15个创意的 3D 字体版式作品欣赏
    值得拥有!精心推荐几款超实用的 CSS 开发工具
  • 原文地址:https://www.cnblogs.com/wang2650/p/5288034.html
Copyright © 2011-2022 走看看