Last post Jan 11, 2011 12:24 PM by hoytrobinson
Oct 09, 2008 12:38 PM|FreddieBoo|LINK
I'm pretty new to the world of programming, but i tried searching the web after an answar but keeps coming up empty. So, I'm stuck.
So, the school assignment is to build a booking-application for a hotel. At the moment, it just consists of two calendars (end date/start date), two dropdownlists (how many beds/extra beds) and a submit button. This is where I am at the moment:
--------- start of code------------------
protected void Button1_Click(object sender, EventArgs e)
DataClassesDataContext db = new DataClassesDataContext();
//retrieve the year, month and day from the first calendar
DateTime dt = Calendar1.SelectedDate;
int startyear = dt.Year;
int startmonth = dt.Month;
int startday = dt.Day;
//mash them together
string s1 = startyear.ToString() + startmonth.ToString() + startday.ToString();
//convert back to int
int start = Int32.Parse(s1);
//retrieve the year, month and day from the second calendar
DateTime dt2 = Calendar2.SelectedDate;
int endyear = dt.Year;
int endmonth = dt.Month;
int endday = dt.Day;
string s2 = endyear.ToString() + endmonth.ToString() + endday.ToString();
int end = Int32.Parse(s2);
var q = from c in db.rooms
where c.beds.Equals(DropDownList1.SelectedValue) && c.extrabeds.Equals(DropDownList2.SelectedValue)
foreach (var qObj in q)
int i = qObj.roomid;
var s = from d in db.rentrooms select d.startdate;
foreach (var d in s)
if (i > 0 && start >= s) //here's where i get the error
var end = from f in db.rentrooms select f.enddate;
------------------- End of Code ----------------
The two columns startdate and enddate are both of the datatype "int". And I've also checked the "Linq to SQL Class", and they are set to "System.Int32" there too.
I know, its pretty messy. But I am at the moment a messy programmer [:)]
Anyway, I get the following error:
Operator '>=' cannot be applied to operands of type 'int' and 'System.Linq.IQueryable<int?>'
I really don't understand why. I'm not asking for help to the entire homework offcourse, just why that line of code isn't working.
Appreciate any, and all, help!
Oct 09, 2008 12:52 PM|ecbruck|LINK
The following statement:
var s = from d in db.rentrooms select d.startdate
returns an IQueryable of type int instead of a single int Therefore, the error simply states that you can't compare an IQueryable of type int with a single int. If you still want to use this logic check, then you must ensure that "s" returns a single int
Oct 09, 2008 02:04 PM|FreddieBoo|LINK
Thanks for the quick response!
Yes, I see that it returns the wrong type of int. I've known about Linq for about a week now, so honestly I really don't know what a IQuearyable<int> is...
But can I somehow make it return a single int, or somehow convert it to a normal int?
Oct 09, 2008 02:16 PM|ecbruck|LINK
IQueryable<int> is a queryable collection of int items. You can use the following to retreive the first int found in the collection:
var s = (from d in db.rentrooms select d.startdate).First()
Jan 11, 2011 12:24 PM|hoytrobinson|LINK
You're Awesome ECBruck!