• 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;
                    }

  • 相关阅读:
    ORACLE时间字段取年、月、日、季度【转】
    Oracle查询指定索引提高查询效率【转】
    ORACLE常用命令【转】
    ORACLE中LOB字段的使用和维护
    Oracle建立DBLINK的详细步骤记录【转】
    Oracle实用日期函数总结[转]
    js脚本中过滤特殊字符的正则表达式
    获取上一页面的URL的方法
    Repeat控件绑定数据格式显示
    我刚做的一个TreeView的CheckBox进行选中插入数据库,从数据库中读取数据后让CheckBox勾选的代码!
  • 原文地址:https://www.cnblogs.com/hutie1980/p/4680116.html
Copyright © 2020-2023  润新知