I try to call storerprocedure in LINQ but this show error
i try this sp
- ALTER procedure [dbo].[grid_data]
- @region varchar(50),
- @fromdate datetime,
- @todate datetime
- as
- Select tblRV.ID as ID, tblRV.Owner, tblRV.Regno,
- (Select Count(*) as total from tblvv WHERE MID = tblRV.ID and Name <> '')
- as total,tblRV.MA, tblRV.MS
- from tblReg inner join tblRV On tblReg.RID = tblRV.RID
- WHERE tblReg.StartDate >= @fromdate AND tblReg.EndDate <= @todate
- and tblReg.Region = @region
- order by tblRV.Owner
- [WebMethod]
- public static string search_data(DateTime fromdate, DateTime todate, string region)
- {
- try
- {
- string result = "";
- TrackDataEntities1 ts = new TrackDataEntities1();
- var dq = ts.griddata(fromdate, todate, region);
- DataTable dt = new DataTable();
- dt.Columns.Add("ID", typeof(int));
- dt.Columns.Add("Owner", typeof(string));
- dt.Columns.Add("RegNo", typeof(string));
- dt.Columns.Add("total", typeof(string));
- dt.Columns.Add("MA", typeof(string));
- dt.Columns.Add("MS", typeof(string));
- foreach (var c in dq)
- {
- dt.Rows.Add(c.ID, c.owner, c.RegNo, c.total, c.MA, c.MS);
- }
- result = DataSetToJSON(dt);
- return result;
- }
- catch (Exception)
- {
- throw new Exception();
- }
- }
- public static string DataSetToJSON(DataTable dt)
- {
- Dictionary<string, object> dict = new Dictionary<string, object>();
- object[] arr = new object[dt.Rows.Count + 1];
- for (int i = 0; i <= dt.Rows.Count - 1; i++)
- {
- arr[i] = dt.Rows[i].ItemArray;
- }
- dict.Add("response", arr);
- JavaScriptSerializer json = new JavaScriptSerializer();
- return json.Serialize(dict);
- }
foreach (var c in dq)
foreach statement cannot operate on variables of type 'int' because 'int' does not contain a public definition for 'GetEnumerator'
6 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
scropio gurlPosted Jul 26, 2016, 2:21 AM
check image http://i.stack.imgur.com/w0gpP.png
my sp return return 42 rows but when i run this code show me 577 row in table.. whereas there is not any error
scropio gurlPosted Jul 25, 2016, 3:14 AM
Manas MohapatraPosted Jul 25, 2016, 3:13 AM
Bikesh SrivastavaPosted Jul 25, 2016, 3:11 AM
scropio gurlPosted Jul 25, 2016, 3:09 AM
Bikesh SrivastavaPosted Jul 25, 2016, 3:04 AM