<i id='j8vD7'><tr id='j8vD7'><dt id='j8vD7'><q id='j8vD7'><span id='j8vD7'><b id='j8vD7'><form id='j8vD7'><ins id='j8vD7'></ins><ul id='j8vD7'></ul><sub id='j8vD7'></sub></form><legend id='j8vD7'></legend><bdo id='j8vD7'><pre id='j8vD7'><center id='j8vD7'></center></pre></bdo></b><th id='j8vD7'></th></span></q></dt></tr></i><div id='j8vD7'><tfoot id='j8vD7'></tfoot><dl id='j8vD7'><fieldset id='j8vD7'></fieldset></dl></div>
  • <small id='j8vD7'></small><noframes id='j8vD7'>

        • <bdo id='j8vD7'></bdo><ul id='j8vD7'></ul>
      1. <tfoot id='j8vD7'></tfoot>
        <legend id='j8vD7'><style id='j8vD7'><dir id='j8vD7'><q id='j8vD7'></q></dir></style></legend>
      2. 如何将一列插入到两个现有列之间的数据集中?

        时间:2023-06-05

      3. <tfoot id='Mb4UR'></tfoot>

          <small id='Mb4UR'></small><noframes id='Mb4UR'>

                <bdo id='Mb4UR'></bdo><ul id='Mb4UR'></ul>
                  <tbody id='Mb4UR'></tbody>
              • <legend id='Mb4UR'><style id='Mb4UR'><dir id='Mb4UR'><q id='Mb4UR'></q></dir></style></legend>
              • <i id='Mb4UR'><tr id='Mb4UR'><dt id='Mb4UR'><q id='Mb4UR'><span id='Mb4UR'><b id='Mb4UR'><form id='Mb4UR'><ins id='Mb4UR'></ins><ul id='Mb4UR'></ul><sub id='Mb4UR'></sub></form><legend id='Mb4UR'></legend><bdo id='Mb4UR'><pre id='Mb4UR'><center id='Mb4UR'></center></pre></bdo></b><th id='Mb4UR'></th></span></q></dt></tr></i><div id='Mb4UR'><tfoot id='Mb4UR'></tfoot><dl id='Mb4UR'><fieldset id='Mb4UR'></fieldset></dl></div>

                1. 本文介绍了如何将一列插入到两个现有列之间的数据集中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用 C# 在现有数据集中插入一列.

                  I'm trying to insert a column into an existing DataSet using C#.

                  作为一个例子,我有一个如下定义的数据集:

                  As an example I have a DataSet defined as follows:

                  DataSet ds = new DataSet();
                  ds.Tables.Add(new DataTable());
                  ds.Tables[0].Columns.Add("column_1", typeof(string));
                  ds.Tables[0].Columns.Add("column_2", typeof(int));
                  ds.Tables[0].Columns.Add("column_4", typeof(string));
                  

                  稍后在我的代码中,我想在第 2 列和第 4 列之间插入一列.

                  later on in my code I am wanting to insert a column between column 2 and column 4.

                  DataSet 有添加列的方法,但我似乎找不到插入列的最佳方法.

                  DataSets have methods for adding a column but I can't seem to find the best way in insert one.

                  我想写一些类似下面的东西......

                  I'd like to write something like the following...

                  ...Columns.InsertAfter("column_2", "column_3", typeof(string))
                  

                  最终结果应该是一个包含以下列的表的数据集:column_1 column_2 column_3 column_4

                  The end result should be a data set that has a table with the following columns: column_1 column_2 column_3 column_4

                  而不是:column_1 column_2 column_4 column_3 这是 add 方法给我的

                  rather than: column_1 column_2 column_4 column_3 which is what the add method gives me

                  肯定有办法做这样的事情.

                  surely there must be a way of doing something like this.

                  编辑...只是想根据下面的一些评论澄清我对 DataSet 所做的事情:

                  Edit...Just wanting to clarify what I'm doing with the DataSet based on some of the comments below:

                  我正在从存储的程序.然后我必须添加数据集的附加列然后将其转换为 Excel文档.我无法控制存储过程返回的数据所以我必须在之后添加列事实.

                  I am getting a data set from a stored procedure. I am then having to add additional columns to the data set which is then converted into an Excel document. I do not have control over the data returned by the stored proc so I have to add columns after the fact.

                  推荐答案

                  您可以使用 DataColumn.SetOrdinal() 用于此目的的方法.

                  You can use the DataColumn.SetOrdinal() method for this purpose.

                  DataSet ds = new DataSet();
                  ds.Tables.Add(new DataTable());
                  ds.Tables[0].Columns.Add("column_1", typeof(string));
                  ds.Tables[0].Columns.Add("column_2", typeof(int));
                  ds.Tables[0].Columns.Add("column_4", typeof(string));
                  ds.Tables[0].Columns.Add("column_3", typeof(string));
                  //set column 3 to be before column 4
                  ds.Tables[0].Columns[3].SetOrdinal(2);
                  

                  这篇关于如何将一列插入到两个现有列之间的数据集中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:恒定错误中的新行 下一篇:插入一个 IEnumerable&lt;T&gt;带有 Dapper 错误的

                  相关文章

                  最新文章

                  <small id='kY96x'></small><noframes id='kY96x'>

                  <legend id='kY96x'><style id='kY96x'><dir id='kY96x'><q id='kY96x'></q></dir></style></legend>
                2. <tfoot id='kY96x'></tfoot>
                  • <bdo id='kY96x'></bdo><ul id='kY96x'></ul>

                  <i id='kY96x'><tr id='kY96x'><dt id='kY96x'><q id='kY96x'><span id='kY96x'><b id='kY96x'><form id='kY96x'><ins id='kY96x'></ins><ul id='kY96x'></ul><sub id='kY96x'></sub></form><legend id='kY96x'></legend><bdo id='kY96x'><pre id='kY96x'><center id='kY96x'></center></pre></bdo></b><th id='kY96x'></th></span></q></dt></tr></i><div id='kY96x'><tfoot id='kY96x'></tfoot><dl id='kY96x'><fieldset id='kY96x'></fieldset></dl></div>