6
Answers

SQL to LINQ query no result

scropio gurl

scropio gurl

8y
440
1
I try this SQL query and this query show results'
 
  1. select  distinct   
  2. tblvv.MID,  
  3. tblrv.ownername,  
  4.   
  5. from tblvv  
  6. join tblrv on tblrv.ID=tblvv.MID  
  7. join tblre on tblre.RID = tblrv.RID  
  8. WHERE tblre.Region ='UK'  and  
  9. StartDate = '2014-02-01 00:00:00.000' AND   
  10. EndDate = '2014-02-28 23:59:59.000'  
  11. order by  
  12. tblrv.ownername  
and then i try to convert this query in LINQ
  1. try    
  2.            {    
  3.                  
  4.                DateTime frmdate = Convert.ToDateTime(fromdate.Value.Trim().Split('T')[0]);    
  5.                DateTime tdatee = Convert.ToDateTime(todate.Value.Trim().Split('T')[0]);    
  6.                string regionvalue = regiondrop.SelectedValue;    
  7.                T1 ts = new Ts1();    
  8.                   
  9.                var dq = (from vv in ts.tblvv    
  10.                          join rv in ts.tblrv on vv.MID equals rv.ID    
  11.                          join re in ts.tblre on rv.RID equals re.RID    
  12.                          where    
  13.                          re.Region == regionvalue    
  14.                         && re.StartDate == frmdate    
  15.                          && re.EndDate == tdatee    
  16.                          orderby rv.OwnerName    
  17.                          select new    
  18.                          {    
  19.                                
  20.                              ownername = rv.OwnerName,    
  21.                              MID= vv.MID,    
  22.                                  
  23.     
  24.                          }).ToList();    
  25.                             
  26.                GridView1.DataSource = dq;    
  27.                GridView1.DataBind();    
  28.     
  29.            }    
  30.            catch (Exception)    
  31.            {    
  32.                GridView1.Visible = false;    
  33.                Label4.Text = ("No Data");    
  34.     
  35.            }    
  36.    
 
 
but this above query not show any result
when i write || this sign on this line
  1. && re.StartDate == frmdate  
like
  1. || re.StartDate == frmdate  
then query shows so many records and this records are totally different from records which is in SQL query
also when i set break point there is not any error occurred
any solution?
Answers (6)