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
PathWest 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.