如何将Arraylist添加到DataTable的特定列中? [英] How to add a Arraylist in to a specific column of DataTable?

查看:90
本文介绍了如何将Arraylist添加到DataTable的特定列中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Arraylist添加到DataTable的特定列中,例如,将名称为"mylist"的Arraylist中的所有项添加到DataTable名称为mydatatable的第5列的行中,就像将数组项添加到MSexcel列的单元格.我尝试以下代码:

How to add a Arraylist in to a specific column of DataTable, for example, add all the items in Arraylist of name ''mylist'' to the rows of 5th column of the DataTable name mydatatable, just like add array items into the cells of MSexcel columns. I try this code:

foreach(string item in mylist)    
{    
  mydatatable.Rows.Add(item);    
}


但是,当我使用此代码时,数据总是填充到表的第一列中,而当我添加列索引或列名时,我会收到错误消息.那么有人对此有任何想法吗?并提前感谢您的时间


But when i am using this code, the data always fill into first column of the table, and when I am adding column index or column name i am getting error message. So anyone have any idea about it? And Thanks in advance for your time

推荐答案

如果我正确理解了您的问题,则无法将数组添加到单行的单列中.

您可以执行的操作是,可以将数组的内容添加到同一行的几列或几行中.数据表是二维的,因此单个单元"不能承载多个值.但是,如果数据是XML字符串,则该值可以包含多个值".
If I understood your question correctly, you cannot add an array to a single column on a single row.

What you can do, you can add the contents of an array either to several columns of the same row or on several rows. A datatable is two dimensional so a single ''cell'' cannot host more than one value. However that value can contain several ''values'' if the data is for example an XML string.


这篇关于如何将Arraylist添加到DataTable的特定列中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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