tags:

views:

59

answers:

1

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

A: 

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
  }
}
AllenG
LINQ? Then: `var nonMatching = ASSETS.Where( asset => !ASSETS_MASTER_SERIALSNOS.CONTAINS(asset.SerialNumber) )/*.ToList()*/;`
ANeves
Ok, so what is the gap between barely know how to spell "linq" to wire this up in a .net 3.5 c# web app? And if you can, point me to some tutorials that would benefit me with this.Lot of different posts tell me to use Linq, so it is inevitable (Must find a way to stop fighting the change... :) )
Eric
@sr pt- true.@Eric - I would recommend downloading LinqPad (look for it on google or bing). That site also has a good set of tutorials about basic LINQ syntax and usage. As for wiring it into your web app, it's really like any other form of connection. I would suggest either using EF (right-click your project, add->new item->ADO.NET Entity Model) or Linq-2-SQL (same procedure, but look for Linq-to-Sql classes).
AllenG