TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
scropio gurl
NA
147
99.1k
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
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
and code
[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);
}
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'
Reply
Answers (
6
)
Hot to convert this sql query in linq.
Rows return in SP and in LINQ