First, few things:
1.
var
is a compile time constant and its scope remains within if{...} or else{...} (in your case). In general within parenthesis {...}
2. The LINQ statement gets executed only when use the LHS variable in the statement.
4. Syntax of the statement is wrong.
3. Do not mix LINQ and SqlCommand. Use either of them.
So,
First,
if(Status==1)
{
var Lqry = from A in DC.CLRN_Tables
join B in DC.CLRN_Tables2 on R.ID equals B.ID
where (A.STATUS == "1") && (B.iStatus == 1)
SqlCommand cmd = (SqlCommand)DC.GetCommand(Lqry);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dsTR);
}
if(Status==2)
{
var Lqry = from A in DC.CLRN_Tables
join B in DC.CLRN_Tables2 on R.ID equals B.ID
where (A.STATUS == "1") &(B.iStatus == 2)
SqlCommand cmd = (SqlCommand)DC.GetCommand(Lqry);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dsTR);
}
By doing this, the scope of
Lqry
remains within
if
Second,
The LINQ statement gets executed when you use it. What I mean by this is, when you write this
var Lqry = from A in DC.CLRN_Tables
join B in DC.CLRN_Tables2 on R.ID equals B.ID
where (A.STATUS == "1") && (B.iStatus == 1)
the statement does not execute.
To execute you need to use this and perform some actions on it. For example, Lqry.Count() perhaps.
Third,
Syntax: A valid statement would look like
List<int> someCollection = new List<int>() { 3,6,9,12,1,17,4 };
var result = from x in someCollection
select x;
result
would be
IEnumerable<int>
So, in the above query, the please change the syntax.
Perhaps,
var Lqry = from A in DC.CLRN_Tables
join B in DC.CLRN_Tables2 on R.ID equals B.ID
where (A.STATUS == "1")&&(B.iStatus == 1)
select A;
Fourth,
Do not mix LINQ and SqlCommand. It is always better to have either of them.
Fix these minor things and your code should work.