将DataTable转换为对象

将DataTable转换为对象

本文介绍了将DataTable转换为对象[,]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将数据表转换为数组?



将我的转换器从DataTable转换为对象[,]

  uint rows =(uint)table.Rows.Count; 
uint columns =(uint)table.Columns.Count;

var data = new object [rows,columns];
int i = 0;
foreach(Table.DefaultView中的System.Data.DataRowView drv)
{
System.Data.DataRow ViewRow = drv.Row;
data [i] = drv.Row.ItemArray.Clone()as object []; //错误的[]中的索引数目;预期2

i ++;
}


解决方案
  uint rows =(uint)table.Rows.Count; 
uint columns =(uint)table.Columns.Count;

var data = new object [rows,columns];
int i = 0;
foreach(table.DefaultView中的System.Data.DataRowView drv)
{($ x $ x $ x $ x


$ Data.DataRow ViewRow = drv.Row;
data [i,x] = drv [x];

i ++;
}
}


How convert DataTable to Array?

Source my converter from DataTable to object[,]

        uint rows = (uint)table.Rows.Count;
        uint columns = (uint)table.Columns.Count;

        var data = new object[rows, columns];
        int i = 0;
        foreach (System.Data.DataRowView drv in table.DefaultView)
        {
            System.Data.DataRow ViewRow = drv.Row;
            data[i] = drv.Row.ItemArray.Clone() as object[];// Wrong number of indices inside []; expected 2

            i++;
        }
解决方案
uint rows = (uint)table.Rows.Count;
uint columns = (uint)table.Columns.Count;

var data = new object[rows, columns];
int i = 0;
foreach (System.Data.DataRowView drv in table.DefaultView)
{
    for( int x = 0; x<columns; x++)
{
    System.Data.DataRow ViewRow = drv.Row;
    data[i, x] = drv[x];

    i++;
}
}

这篇关于将DataTable转换为对象[,]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:35