用arraylist填充数据集 [英] populating a dataset with arraylist
本文介绍了用arraylist填充数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个arraylist用作Grid的数据源.如何获得与新数据集中的arraylist完全相同的值?
谢谢
Amit
hey everyone,
i have a arraylist which is used as a datasource for Grid.How can i get the exact same values that are in arraylist in a new datset??..
thanks
Amit
推荐答案
如何解决
public DataSet ConvertArraylistToDataSet(ArrayList arrayList)
{
dsEntityReturned = new DataSet();
dtEntityReturned = new DataTable();
dsEntityReturned.Tables.Add(dtEntityReturned);
dsEntityReturned.Tables[0].Columns.Add("NAME", System.Type.GetType("System.Object"));
foreach (object obj in arrayList)
{
DataRow rows = dsEntityReturned.Tables[0].NewRow();
rows[0] =obj; // here the error blows up
dsEntityReturned.Tables[0].Rows.Add(rows);
//return dsEntityReturned;
}
// return null;
}
HTH
HTH
希望此 [ ^ ]可能会为您提供帮助.
Hope this[^] might help you.
为此,您需要先将arraylist记录传输到临时DataTable,然后使用DataSet来保存该DataTable.
然后将DataSet设置为DataGridView的DataSource属性,并将DataTable设置为DataMember属性.
For this purpose you need to first transfer arraylist records to a temporary DataTable then use a DataSet to hold that DataTable.
Then put DataSet to DataSource property and DataTable to DataMember property of your DataGridView.
这篇关于用arraylist填充数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文