scropio gurl

scropio gurl

  • NA
  • 147
  • 96.8k

Call SP in LINQ

Jul 25 2016 2:36 AM
I try to call storerprocedure in LINQ but this show error
i try this sp
  1. ALTER procedure [dbo].[grid_data]  
  2. @region varchar(50),  
  3. @fromdate datetime,  
  4. @todate datetime  
  5. as  
  6. Select tblRV.ID as ID, tblRV.Owner, tblRV.Regno,  
  7.        (Select Count(*) as total from tblvv WHERE MID = tblRV.ID and Name <> '')  
  8.                 as total,tblRV.MA, tblRV.MS   
  9. from tblReg inner join tblRV On tblReg.RID = tblRV.RID  
  10. WHERE tblReg.StartDate >= @fromdate AND tblReg.EndDate <= @todate   
  11. and tblReg.Region = @region  
  12. order by tblRV.Owner  
and code
  1. [WebMethod]  
  2.         public static string search_data(DateTime fromdate, DateTime todate, string region)  
  3.         {  
  4.             try  
  5.             {  
  6.                 string result = "";  
  7.                 TrackDataEntities1 ts = new TrackDataEntities1();  
  8.                 var dq = ts.griddata(fromdate, todate, region);  
  9.                 DataTable dt = new DataTable();  
  10.   
  11.                 dt.Columns.Add("ID"typeof(int));  
  12.                 dt.Columns.Add("Owner"typeof(string));  
  13.                 dt.Columns.Add("RegNo"typeof(string));  
  14.                 dt.Columns.Add("total"typeof(string));  
  15.                 dt.Columns.Add("MA"typeof(string));  
  16.                 dt.Columns.Add("MS"typeof(string));  
  17.                 foreach (var c in dq)  
  18.                 {  
  19.                     dt.Rows.Add(c.ID, c.owner, c.RegNo, c.total, c.MA, c.MS);  
  20.                 }  
  21.   
  22.                 result = DataSetToJSON(dt);  
  23.   
  24.                 return result;  
  25.             }  
  26.             catch (Exception)  
  27.             {  
  28.                 throw new Exception();  
  29.   
  30.   
  31.             }  
  32.   
  33.         }  
  34.        
  35.         public static string DataSetToJSON(DataTable dt)  
  36.         {  
  37.   
  38.             Dictionary<stringobject> dict = new Dictionary<stringobject>();  
  39.   
  40.             object[] arr = new object[dt.Rows.Count + 1];  
  41.   
  42.             for (int i = 0; i <= dt.Rows.Count - 1; i++)  
  43.             {  
  44.                 arr[i] = dt.Rows[i].ItemArray;  
  45.             }  
  46.    
  47.             dict.Add("response", arr);  
  48.   
  49.             JavaScriptSerializer json = new JavaScriptSerializer();  
  50.             return json.Serialize(dict);  
  51.               
  52.         }  
 but this show error on this line 
foreach (var c in dq)
 
 foreach statement cannot operate on variables of type 'int' because 'int' does not contain a public definition for 'GetEnumerator' 
 

Answers (6)