本文介绍了将数据表添加到现有数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友, 我有一个数据集,其中有多个表在索引0,1,2. 我想在执行的索引1处过滤表数据,并且在该方法(返回过滤后的数据表)返回数据表之后.我只想将其添加到索引1处的现有数据集中. 我不能那样做. 请帮忙. 谢谢 Varun Sareen
Dear Friends, I have a dataset in which there are multiple tables for e.g. at index 0,1,2. I want to filter the table data at index 1, which i am doing and after the method (which returns the filtered datatable) returns the datatable..I want to add it to my existing dataset at index 1 only. I am not able to do that. Kindly help. Thanks Varun Sareen
推荐答案//<summary> /// Routine to filter first table and replace exiting table with filtered records. // </summary> // <param name="sourceSet">Dataset instance to be manipulated</param>\n private void _FilterAndInsert(DataSet sourceSet) { ///Apply your filter clauses in Select() function parameter DataRow[] rows = sourceSet.Tables[0].Select("filter clauses here..."); ///Get the structure of source table DataTable tempTable = sourceSet.Tables[0].Clone(); ///Add the filtered rows in temp table foreach (DataRow row in rows) { tempTable.Rows.Add(row.ItemArray); } tempTable.AcceptChanges(); ///Create new dataset DataSet resultSet = new DataSet(); ///Add temp table at first index or modify this code sequence as you require resultSet.Tables.Add(tempTable); for (int index = 1; index < sourceSet.Tables.Count; index++) { ///Set the copy of source table in local instance DataTable tableToAdd = sourceSet.Tables[index].Copy(); ///Remove from source to avoid any exceptions sourceSet.Tables.RemoveAt(index); ///Add the copy to result set resultSet.Tables.Add(tableToAdd); } ///Set the copy to source table from result set sourceSet = resultSet.Copy(); }
ADO.NET使您可以创建DataTable对象并将其添加到现有DataSet中.您可以使用PrimaryKey和Unique属性为DataTable设置约束信息. 有关更多信息,请检查此 msdn.microsoft/en-us/library/aeskbwf7%28v = vs.80%29.aspx [ ^ ] ADO.NET enables you to create DataTable objects and add them to an existing DataSet. You can set constraint information for a DataTable by using the PrimaryKey and Unique properties. For more information check this msdn.microsoft/en-us/library/aeskbwf7%28v=vs.80%29.aspx[^]
更多推荐
将数据表添加到现有数据集
发布评论