zoukankan      html  css  js  c++  java
  • ds.Merge 与 ds.Tables[0].Merge 的用法

                DataSet ds = new DataSet();

                SqlConnection conn = new SqlConnection(ConnectionStr);
                SqlCommand cmd = new SqlCommand();
                cmd.CommandTimeout = 180;

     SqlParameter[] parameters = new SqlParameter[]{
                    new SqlParameter("@strNum",SqlDbType.NVarChar,50),
                    new SqlParameter("@strDjStartDate",SqlDbType.NVarChar,10),
                    new SqlParameter("@strDjEndDate",SqlDbType.NVarChar,10),
                    new SqlParameter("@strScStartDate",SqlDbType.NVarChar,10),
                    new SqlParameter("@strScEndDate",SqlDbType.NVarChar,10),
                    new SqlParameter("@strCreator",SqlDbType.NVarChar,50),
                    new SqlParameter("@str_tb",SqlDbType.NVarChar,50),
                   };

                    ////1
                    parameters[0].Value = strNum;
                    parameters[1].Value = strDjStartDate;
                    parameters[2].Value = strDjEndDate;
                    parameters[3].Value = strScStartDate;
                    parameters[4].Value = strScEndDate;
                    parameters[5].Value = strCreator;
                    parameters[6].Value = "[auto_ZYQA-P-07-06_myFields]";

                    try
                    {
                        PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "Proc_Export8DPZYC", parameters);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet, "t1");
                        cmd.Parameters.Clear();
                        ds.Merge(dataSet, false, MissingSchemaAction.Add);
                    }
                    catch
                    {
                        conn.Close();
                        throw;
                    }

                    ////2
                    parameters[0].Value = strNum;
                    parameters[1].Value = strDjStartDate;
                    parameters[2].Value = strDjEndDate;
                    parameters[3].Value = strScStartDate;
                    parameters[4].Value = strScEndDate;
                    parameters[5].Value = strCreator;
                    parameters[6].Value = "[auto_ZYQA-P-07-06_myFields_12]";
                    try
                    {
                        PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "Proc_Export8DPZYC", parameters);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet, "t2");
                        cmd.Parameters.Clear();
                        ds.Tables[0].Merge(dataSet.Tables[0], false, MissingSchemaAction.Add);
                    }
                    catch
                    {
                        conn.Close();
                        throw;
                    }

                    ////3
                    parameters[0].Value = strNum;
                    parameters[1].Value = strDjStartDate;
                    parameters[2].Value = strDjEndDate;
                    parameters[3].Value = strScStartDate;
                    parameters[4].Value = strScEndDate;
                    parameters[5].Value = strCreator;
                    parameters[6].Value = "[auto_ZYQA-P-07-06_myFields_13]";
                    try
                    {
                        PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "Proc_Export8DPZYC", parameters);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet, "t3");
                        cmd.Parameters.Clear();
                        ds.Tables[0].Merge(dataSet.Tables[0], false, MissingSchemaAction.Add);
                    }
                    catch
                    {
                        conn.Close();
                        throw;
                    }

                    ////4
                    parameters[0].Value = strNum;
                    parameters[1].Value = strDjStartDate;
                    parameters[2].Value = strDjEndDate;
                    parameters[3].Value = strScStartDate;
                    parameters[4].Value = strScEndDate;
                    parameters[5].Value = strCreator;
                    parameters[6].Value = "[auto_ZYQA-P-07-06_myFields_14]";
                    try
                    {
                        PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "Proc_Export8DPZYC", parameters);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet, "t4");
                        cmd.Parameters.Clear();
                        ds.Tables[0].Merge(dataSet.Tables[0], false, MissingSchemaAction.Add);
                    }
                    catch
                    {
                        conn.Close();
                        throw;
                    }

                    ////5
                    parameters[0].Value = strNum;
                    parameters[1].Value = strDjStartDate;
                    parameters[2].Value = strDjEndDate;
                    parameters[3].Value = strScStartDate;
                    parameters[4].Value = strScEndDate;
                    parameters[5].Value = strCreator;
                    parameters[6].Value = "[auto_ZYQA-P-07-06_myFields_15]";
                    try
                    {
                        PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "Proc_Export8DPZYC", parameters);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet, "t5");
                        cmd.Parameters.Clear();
                        ds.Tables[0].Merge(dataSet.Tables[0], false, MissingSchemaAction.Add);
                    }
                    catch
                    {
                        conn.Close();
                        throw;
                    }

                    ////6
                    parameters[0].Value = strNum;
                    parameters[1].Value = strDjStartDate;
                    parameters[2].Value = strDjEndDate;
                    parameters[3].Value = strScStartDate;
                    parameters[4].Value = strScEndDate;
                    parameters[5].Value = strCreator;
                    parameters[6].Value = "[auto_ZYQA-P-07-06_myFields_16]";
                    try
                    {
                        PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "Proc_Export8DPZYC", parameters);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet, "t6");
                        cmd.Parameters.Clear();
                        ds.Tables[0].Merge(dataSet.Tables[0], false, MissingSchemaAction.Add);
                    }
                    catch
                    {
                        conn.Close();
                        throw;
                    }

  • 相关阅读:
    gradle使用笔记
    MaxScale初探
    mariadb-10GTID复制及多源复制
    Shell中的循环语句实例
    Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
    学习MongoDB--(5-2):索引(查看索引的使用,管理索引)
    MongoDB索引管理
    mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别
    MongoDB增加用户、删除用户、修改用户读写权限及只读权限(注:转载于http://www.2cto.com/database/201203/125025.html)
    MongoDB创建数据库
  • 原文地址:https://www.cnblogs.com/hutie1980/p/4680116.html
Copyright © 2011-2022 走看看