有两个DataTable 在c#里怎样才能象数据库里一样取t得交集 Tb1 Tb2id Tb2id ID Name1 2 2 qw2 3 3 qw3 4 4 qw 合成 一个Tb有 id,Tb2id ,Name字段别说在数据库里处理 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果 DataSet 中的表之间存在关系,则可以使用 DataRowView 的 CreateChildView 方法为父表中的行创建一个 DataView,包含相关子表中的行。例如,以下代码显示按 CategoryName 和 ProductName 的字母顺序排序的 Categories 及其相关 Products。DataTable catTable = catDS.Tables["Categories"];DataTable prodTable = catDS.Tables["Products"];// Create a relation between the Categories and Products tables.DataRelation relation = catDS.Relations.Add("CatProdRel", catTable.Columns["CategoryID"], prodTable.Columns["CategoryID"]);// Create DataViews for the Categories and Products tables.DataView catView = new DataView(catTable, "", "CategoryName", DataViewRowState.CurrentRows);DataView prodView;// Iterate through the Categories table.foreach (DataRowView catDRV in catView){ Console.WriteLine(catDRV["CategoryName"]); // Create a DataView of the child product records. prodView = catDRV.CreateChildView(relation); prodView.Sort = "ProductName"; foreach (DataRowView prodDRV in prodView) Console.WriteLine("\t" + prodDRV["ProductName"]);}继续抄MSDN~! MSDN上dataset类讲的很详细,例子也很多,要下班了就不继续抄了~~! C# WebClient下载文件的疑问 关于利用C#编写窗口程序读取西门子PLC实时数据的问题。 C#API读写串口问题 对开发.NET项目的一些疑问 存储过程 触发器 事务 怎样理解 C#Winform:窗体间数据调用一般是怎么做的? 学习 大家帮忙 c# 画 时间电流曲线 c#的编译环境! C# 事件 怎么限定文本框只能输大写字母?
DataTable prodTable = catDS.Tables["Products"];// Create a relation between the Categories and Products tables.
DataRelation relation = catDS.Relations.Add("CatProdRel",
catTable.Columns["CategoryID"],
prodTable.Columns["CategoryID"]);// Create DataViews for the Categories and Products tables.
DataView catView = new DataView(catTable, "", "CategoryName",
DataViewRowState.CurrentRows);
DataView prodView;// Iterate through the Categories table.
foreach (DataRowView catDRV in catView)
{
Console.WriteLine(catDRV["CategoryName"]); // Create a DataView of the child product records.
prodView = catDRV.CreateChildView(relation);
prodView.Sort = "ProductName"; foreach (DataRowView prodDRV in prodView)
Console.WriteLine("\t" + prodDRV["ProductName"]);
}
继续抄MSDN~!