I currently have the :below: code for generating a list of all current ‘rides’ in an sql db table.. However, it seems that although there is data in the table, I am not able to access it. Am I missing an initialization step? Other thoughts?
using (RamRideOpsEntities myEntities = new RamRideOpsEntities())
{
var adminOptions = (from a in myEntities.AdminOptions
select new { a.ValidDate1, a.ValidDate2 }).First();
var allRides = (from r in myEntities.Rides
where (r.TimeOfCall == adminOptions.ValidDate1 ||
r.TimeOfCall == adminOptions.ValidDate2)
orderby r.TimeOfCall descending
select r).ToList();
TextBox1.Text = allRides[0].Name; // <- Seems there are no existing objects as rides[0] is out of bounds
}
Have you checked the adminOptions variable to confirm whether or not it contains what you intend for it to contain?
The ValidDate1 and ValidDate2 properties of the adminOptions variable are the only conditions of the allRides query that are external to the Rides table, so my guess is that the allRides query might be OK; however, there may be an issue with the adminOptions query.