使用double tryperse将数据表从字符串转换为double [英] convert datatable from string to double with double tryperse

查看:109
本文介绍了使用double tryperse将数据表从字符串转换为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Guys

Any example on how to convert a datatable with 4 rows and 4 columns from string to double so I could add the rows to a double type datatable ? thanks

推荐答案

很容易将其作为通用方法:
Pretty easy to make this a generic method:
// required
using System.Data;

private DataTable ConvertDataTable<T>(DataTable sourceTable)
{
    DataTable clone = sourceTable.Clone();

    for (int i = 0; i < clone.Columns.Count; i++) clone.Columns[i].DataType = typeof(T);

    foreach (DataRow row in sourceTable.Rows) clone.ImportRow(row);

    return clone;
}

// usage
// private DTAsDouble;
// DTAsDouble = ConvertDataTable<double>(currentStringDataTable);


这篇关于使用double tryperse将数据表从字符串转换为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆