Click here to Skip to main content
15,886,772 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to populate gridview from storeprocedure using LINQ. I have created storeprocedure and dragged it to .dbml file.

My Store proc is as follow:

SQL
create proc sp_getReportDateWise
@fromDate date,
@toDate date
as select * from tblreport where Date BETWEEN @fromDate AND @toDate


In button click event i have the following code:
C#
LinqSampleDataContext db = new LinqSampleDataContext();
var report = (from r in db.sp_getReportDateWise(Convert.ToDateTime(txtFromDate.Text), Convert.ToDateTime(txtToDate.Text)) select r).ToList();
gridviewResult.DataSource = report;
gridviewResult.DataBind();


It shows no error and doest even populate the data. Please help me to populate gridview with store proc using LINQ to Sql Class.
Posted
Updated 9-Apr-13 19:34pm
v3

1 solution

Hi,

try by modifying the LINQ query like below.
C#
var report = (from r in db.sp_getReportDateWise(Convert.ToDateTime(txtFromDate.Text), Convert.ToDateTime(txtToDate.Text)) select r).CopyToDataTable();

also, make sure the procedure is giving result set and the gridview is having bound fields or template fields.

hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900