Where have I said it was just problem with DateTime? I said that I was getting error messages on two lines, but my problem is that my code doesn't work. What I want to do is when the user adds a new meeting it should be a warning about the meeting
overlaps another meeting in the same room at that time. That is what I try to achieve, but obviously my code doesn't work. As I said in my previous post, my loop does not go through the entire table, but jumps out after the first time.
string formPlace = ddlPlace.SelectedValue;
string[] dbPlace = { sel.placeID.ToString() };
foreach(string place in dbPlace)
{
if (place == formPlace)
{
if (sel.Starttime <= starttime)
{
if (sel.Starttime >= endtime)
{
Response.Write("Starts before, end after");
}
}
else
{
db.Sammantrades.InsertOnSubmit(sel);
db.SubmitChanges();
}
if (sel.Starttime == starttime)
Response.Write("Starts at the same time");
if (sel.Starttime >= starttime)
{
if (sel.Starttime <= starttime)
{
Response.Write("Starts after and ends before);
}
}
else
{
db.Sammantrades.InsertOnSubmit(sel);
db.SubmitChanges();
}
}
else
{
db.Sammantrades.InsertOnSubmit(sel);
db.SubmitChanges();
}
}
}
Edit: But maybe I should take this in any other thread as it does not have as much to do with LINQ
gunnargren
Member
11 Points
50 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 06, 2012 08:53 AM|LINK
Of course I should have trace the code before I wrote here again, sry.
But now when I have done that, I see that I got the first date and time in my table for this row:
Edit: It seems like my foreach-case does not work, I will try on my on and come back here if I don´t make it.
gunnargren
Member
11 Points
50 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 06, 2012 09:32 AM|LINK
I know I doing something wrong but I can´t figure it out what it is. My loop does not go through the entire table, but jumps out after the first time.
What I am trying to achieve here
is that if the place I chose in my dropdown-list are in my table then it go through my if-statements.
Is I on the right track or am I completely on wrong track?
Excuse my bad english, but I hope you understand what I mean.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 07, 2012 01:43 AM|LINK
What's that??
I don't know your logics at all:(
Just now your problem was DateTime, but now it's place……
gunnargren
Member
11 Points
50 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 12, 2012 08:04 AM|LINK
Sorry for the late reply, have been sick.
Where have I said it was just problem with DateTime? I said that I was getting error messages on two lines, but my problem is that my code doesn't work. What I want to do is when the user adds a new meeting it should be a warning about the meeting overlaps another meeting in the same room at that time. That is what I try to achieve, but obviously my code doesn't work. As I said in my previous post, my loop does not go through the entire table, but jumps out after the first time.
string formPlace = ddlPlace.SelectedValue; string[] dbPlace = { sel.placeID.ToString() }; foreach(string place in dbPlace) { if (place == formPlace) { if (sel.Starttime <= starttime) { if (sel.Starttime >= endtime) { Response.Write("Starts before, end after"); } } else { db.Sammantrades.InsertOnSubmit(sel); db.SubmitChanges(); } if (sel.Starttime == starttime) Response.Write("Starts at the same time"); if (sel.Starttime >= starttime) { if (sel.Starttime <= starttime) { Response.Write("Starts after and ends before); } } else { db.Sammantrades.InsertOnSubmit(sel); db.SubmitChanges(); } } else { db.Sammantrades.InsertOnSubmit(sel); db.SubmitChanges(); } } }Edit: But maybe I should take this in any other thread as it does not have as much to do with LINQ
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 12, 2012 09:34 AM|LINK
Hi,
You have to tell the condition like this:
if(DateTime.HasValue && DateTime.Value=……)
{
………………
}
gunnargren
Member
11 Points
50 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 13, 2012 07:19 PM|LINK
Hi,
Excuse me, but I don´t quite understand what you mean here. Is it here you mean?
if (sel.Starttime <= starttime) { if (sel.Starttime >= endtime) { Response.Write("Starts before, end after"); } }Edit: Thanks for helping me
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Need help - Check start- and end time for a meeting.
Dec 14, 2012 12:24 AM|LINK
I mean your DateTime is a Nullable value, please first check whether it has value, otherwises to do comparation.
Reguards!