【发布时间】:2009-04-26 04:19:41
【问题描述】:
我想匹配两个相同的表:
sourceProducts (productName, ProductionDate, ManID, shipper, distributer)
CommProducts (productName, ProductionDate, ManID, shipper, distributer)
但行数和记录内容可能不同。如何从一个表中选择某个记录 = raw 并从另一个表中获取其克隆记录(例如,检查是否存在相同的记录)?如何使用 LinQ 做到这一点?
更新:这是 LINQ 代码:
protected void checkBtn_Click(object sender, EventArgs e)
{
MyProductsDataContext mySdb = new MyProductsDataContext();
Product mypro = new Product { ManId = int.Parse(TxtManI.Text), ProductName = TxtProN.Text, ProductionDate =DateTime .Parse ( TxtProDat.Text), Shipper = TxtShipI.Text, Distributer = TxtDistI.Text };
var spro = (from p in mySdb.Products
select new { p.ManId, p.ProductName, p.ProductionDate, p.Shipper, p.Distributer }).
Intersect(from s in mySdb.SourceProducts select new { s.ManId, s.ProductName, s.ProductionDate, s.Shipper, s.Distributer });
if (spro != null)
{
LblMessage.Text = "Acceptable product Data Inserted Sucessfully";
InsertData();
}
else
{
LblMessage.Text = "Invalid Product or bad Entry Please retype";
}
}
【问题讨论】:
-
我更新了您的帖子以包含您粘贴在另一个问题下的代码。
-
我想知道您为什么要求用户在您已经拥有所有数据的情况下再次输入所有数据。
标签: c# sql linq linq-to-sql