当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - I want to display the missing (non-matching) records

问题描述:

Is there a way to program the following SQL query

SELECT dbo.Assets_Master.Serial_Number, dbo.Assets_Master.Account_Ident, dbo.Assets_Master.Disposition_Ident

FROM dbo.Assets_Master LEFT OUTER JOIN

dbo.Assets ON dbo.Assets_Master.Serial_Number = dbo.Assets.Serial_Number

WHERE (dbo.Assets.Serial_Number IS NULL)

in c# .net code using dataviews or data relation or something else?

I have a spreadsheet of about 4k rows and a data table that should have the same records but if not I want to display the missing (non-matching) records from the table.

Thanks,

Eric

网友答案:

If you've already got that query, you can just pass that text as a SQL command and pull back the results as a dataset. Better might be setting up your query as a stored procedure and then following the same steps (calling a stored proc is cleaner than writing the SQL by hand).

If you want a way to do it without SQL at all, you could use LINQ to grab an IENUMERABLE of your ASSETS_MASTER serial numbers and another IENUMBERABLE of your ASSETS records. Then something like:

foreach(ASSET asset in ASSETS)
{
  if(!ASSETS_MASTER_SERIALSNOS.CONTAINS(asset.SerialNumber))
  {
    //Do Whatever
  }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: