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'
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Jul 24, 2016, 11:04 PM EDT
scropio gurl145 reputationPosted Jul 24, 2016, 11:09 PM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Jul 24, 2016, 11:11 PM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Jul 24, 2016, 11:13 PM EDT
scropio gurl145 reputationPosted Jul 24, 2016, 11:14 PM EDT
scropio gurl145 reputationPosted Jul 25, 2016, 10:21 PM EDT
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
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts