In a C#.asp.net 2010 web form application that connects to a sql server 2008 r2 database, I would like to write a linq to sql
statement that will translate to:
Select field1 from testtable
where column1='customer' and column2 = 'statename'.
The sql would run using an existing datacontext object.
Can you should me some code that would accomplish this task?
Loading

VulpesRank #55 · 29.2K reputationPosted Jun 7, 2012, 2:10 PM EDT
http://www.hookedonlinq.com/LINQToSQLFAQ.ashx
However, if you're directly executing the query using the ExecuteQuery method, then you need to follow the procedure in this MSDN link to allow for parameters:
http://msdn.microsoft.com/en-us/library/bb399403.aspx
VulpesRank #55 · 29.2K reputationPosted Jun 7, 2012, 10:05 AM EDT
scampercat187 reputationPosted Jun 7, 2012, 11:07 AM EDT
Nattudurai EswaramurthyRank #5,536 · 296 reputationPosted Jun 7, 2012, 8:29 PM EDT
var result = from s in context.tablename
where s.column1 == param1 && s.column2 ==param2
select s.columnname;
Hope this will help u
VulpesRank #55 · 29.2K reputationPosted Jun 8, 2012, 5:48 AM EDT
There's no need to allow for this specifically in the query though you may, of course, need to deal with it in subsequent processing.