• DataTable改变column类型


    1、必须先克隆DataTable

    2、列换类型

    3、逐行往新DataTable赋值,并转换某列类型

    如:

    DataTable dt = diorg.Clone(); //必须先克隆,此时并不包含数据

                dt.Columns[col].DataType = typeof(bool);

                foreach (DataRow row in diorg.Rows)

                {

                    DataRow rowNew = dt.NewRow();

                    for (int i = 0; i < dt.Columns.Count; i++)

                    {

                        if (i == col)

                        {

                            try

                            {

                                rowNew[i] = Convert.ToBoolean(row[i]);

                            }

                            catch { }

                        }

                        else

                            rowNew[i] = row[i];

                    }

                    dt.Rows.Add(rowNew);

                }

                return dt;

  • 相关阅读:
    DRF JWT认证基础
    Shell简单脚本
    DockerFile案例
    Shell基础知识
    DockerFile基础知识
    tensorflow
    使用cv2将图片分割成相等的部分
    序列化心得
    python正则化表达式
    python--匿名函数(lambda)
  • 原文地址:https://www.cnblogs.com/mol1995/p/8325089.html
Copyright © 2020-2023  润新知