Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have 2 where what i loking for is to have (where) (and)
C#
where DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString() 
                                where DB_A448D1_ilgswork.username == txtusername.Text


What I have tried:

C#
var getreminders = (from DB_A448D1_ilgswork in doAction.uni_projects
                                where DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString() 
                                where DB_A448D1_ilgswork.username == txtusername.Text
                                select DB_A448D1_ilgswork).ToList();

            if (getreminders.Count >= 1)
            {
                lbldue.Visible = true;
                lbldue.Text = "You have " + getreminders.Count() + "reminders set for today";
                lbnoldue.Visible = false;
            }
            else
            {
                lbnoldue.Visible = true;
                lbldue.Visible = false;
            }
Posted
Updated 12-Feb-19 1:53am
v4
Comments
Richard Deeming 12-Feb-19 9:48am    
where DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString()


Looks like you're storing dates as strings. Don't do that. Not only does it take up much more space, it also allows invalid values, and leads to problems interpreting strings generated on computers with different regional settings.

Use either DateTime or DateTimeOffset in your model, and use a proper date/time data type in your database.

1 solution

You do not say what kind of error.
I assume that getreminders is null because your query gave no results.
You cannot access the Count property when getreminders is null.
You will get a null reference exception.

Use a debugger and see yourself.


OK. The red line is in your IDE.
Of course an IQueriable does not have a Count property.
You should convert it then to a list.

var getreminders = (from DB_A448D1_ilgswork in doAction.uni_projects
                              where DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString()
                              select DB_A448D1_ilgswork).ToList();
 
Share this answer
 
v3
Comments
el_tot93 12-Feb-19 6:18am    
i get a red line under it
TheRealSteveJudge 12-Feb-19 6:23am    
Please see updated solution.
el_tot93 12-Feb-19 6:24am    
sorry my bro how can i do that ??
TheRealSteveJudge 12-Feb-19 6:34am    
Just replace line 3 to 5 by the example I showed you.
el_tot93 12-Feb-19 6:35am    
thx it work with me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900