zoukankan      html  css  js  c++  java
  • VB.NET 改变datatable数据类型

    Public Shared Function modifyDataTableType(ByVal dt As DataTable, ByVal list As List(Of String), Optional ByVal dectype As Boolean = True) As DataTable
        Dim newDt As DataTable = dt.Clone
        For i As Integer = 0 To list.Count - 1
            If dectype Then
                newDt.Columns(list(i)).DataType = GetType(Decimal)
            Else
                newDt.Columns(list(i)).DataType = GetType(String)
            End If
        Next
    
        For a As Integer = 0 To dt.Rows.Count - 1
            Dim dr As DataRow = newDt.NewRow
            For b As Integer = 0 To dt.Columns.Count - 1
                dr(b) = dt.Rows(a)(b)
            Next
            newDt.Rows.Add(dr)
        Next
        Return newDt
    End Function

    调用如下:

    Dim colNm As String() = {"salesprice", "purchase", "profit", "salesdateys", "profitys"}  //声明需要修改的列名 数组

    Dim newDt As DataTable = Utils.Util.modifyDataTableType(csvDt, colNm.ToList)  //调用上面方法

  • 相关阅读:
    咨询
    xcode技巧
    礼仪
    asi 网络框架
    iOS 开发问题 书籍 价值 改名 创业大赛app
    PS,UI,美工
    运营推广
    多线程 并发 文章
    手机技巧 文章
    javaScript 类文章
  • 原文地址:https://www.cnblogs.com/xlaxx/p/11329360.html
Copyright © 2011-2022 走看看