I don't know GridView very well (or LINQ to SQL), but to rule out deferred execution being the problem you could change "GridViewStaff.DataSource = stafflist;" to "GridViewStaff.DataSource = stafflist.ToList();".
Calling ToList() will execute the query and returns an IList<> instead of IEnumerable<> (which is what your query will be). On Fri, Mar 16, 2012 at 4:49 PM, Peter Maddin <[email protected]>wrote: > I just threw together a quick console application using the same code**** > > ** ** > > static void Main(string[] args)**** > > {**** > > **** > > var conn = ConfigurationManager.ConnectionStrings[ > "PathWestStaffConnectionString"].ConnectionString;**** > > **** > > var staffDetails = new StaffDataContext(conn);**** > > **** > > Console.WriteLine("Testing");**** > > **** > > //This works**** > > var stafflist =**** > > from staff in staffDetails.Staffs**** > > orderby staff.Last_Name**** > > select staff;**** > > ** ** > > ** ** > > //// so does this.**** > > //var stafflist =**** > > // from staff in staffDetails.GetTable<Staff>()**** > > // orderby staff.Last_Name**** > > // select staff;**** > > **** > > foreach (var x in stafflist)**** > > {**** > > var y = x.Last_Name + " : " + x.First_Name;**** > > Console.WriteLine(y);**** > > }**** > > }**** > > ** ** > > I know that with LINQ you get deferred execution, but I am not getting > anything in my GridView**** > > I must be doing something really dumb.**** > > ** ** > > ** ** > > *Regards Peter Maddin* > *Applications Development Officer* > *Path**West Laboratory Medicine WA* > *Phone : +618 6396 4285 (Monday, Wednesday,Friday)* > > *Phone : +618 9346 4372 (Tuesday, Thursday)** > Mobile: 0423 540 825* > *E-Mail : [email protected]; [email protected]* > *The contents of this e-mail transmission outside of the WAGHS network > are intended solely for the named recipient's), may be confidential, and > may be privileged or otherwise protected from disclosure in the public > interest. The use, reproduction, disclosure or distribution of the contents > of this e-mail transmission by any person other than the named recipient(s) > is prohibited. If you are not a named recipient please notify the sender > immediately**.***** > > **** > > ** ** > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Peter Maddin > *Sent:* Friday, 16 March 2012 2:18 PM > *To:* [email protected] > *Subject:* Learning LINQ**** > > ** ** > > I have a new project so I would thought here is an opportunity to embrace > LINQ, or in my case LINQ to SQL (at this stage).**** > > ** ** > > I have a simple SQL Server database and I just want to get retrieve the > records and bind it to a Web GridView – nothing flash.**** > > ** ** > > I have tested this in LINQPad**** > > ** ** > > string con = @"SQL Server Connection String Details goes here";**** > > ** ** > > DataContext db = new DataContext(con);**** > > ** ** > > ** ** > > var realstaff =**** > > from staff in db.GetTable<Staff>()**** > > where staff.Active == true **** > > select staff;**** > > **** > > realstaff.Dump();**** > > ** ** > > This works fine.**** > > ** ** > > In VS20910 in the load event for the GridView I have something similar**** > > ** ** > > protected void GridViewStaff_Load(object sender, EventArgs e)**** > > {**** > > **** > > if (connString != null)**** > > {**** > > Staff_Data = new > PathWestStaffDataContext(connString.ConnectionString);**** > > **** > > //This does not work**** > > //var stafflist =**** > > // from staff in Staff_Data.Staffs**** > > // orderby staff.Last_Name**** > > // select staff;**** > > **** > > // Neither does this.**** > > var stafflist =**** > > from staff in Staff_Data.GetTable<Staff>()**** > > orderby staff.Last_Name**** > > select staff;**** > > **** > > **** > > GridViewStaff.DataSource = stafflist;**** > > GridViewStaff.DataBind();**** > > }**** > > }**** > > ** ** > > I get no errors but all I get is the Title of The GridView and nothing > else.**** > > ** ** > > I would have thought the DataBind() method call would have caused the > query to execute.**** > > ** ** > > I am a complete newbie to this.**** > > Can anyone please tell me what I am doing that is wrong.**** > > ** ** > > *Regards Peter Maddin* > *Applications Development Officer* > *Path**West Laboratory Medicine WA* > *Phone : +618 6396 4285 (Monday, Wednesday,Friday)* > > *Phone : +618 9346 4372 (Tuesday, Thursday) > Mobile: 0423 540 825* > *E-Mail : [email protected]; [email protected]* > *The contents of this e-mail transmission outside of the WAGHS network > are intended solely for the named recipient's), may be confidential, and > may be privileged or otherwise protected from disclosure in the public > interest. The use, reproduction, disclosure or distribution of the contents > of this e-mail transmission by any person other than the named recipient(s) > is prohibited. If you are not a named recipient please notify the sender > immediately**.***** > > **** > > ** ** >
