我不知道如何解决这个错误?计数 [英] I don't know how to solve this error ? count

查看:81
本文介绍了我不知道如何解决这个错误?计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个我喜欢的地方(其中)(和)

 其中 DB_A448D1_ilgswork.DueBy == DateTime。 Today.ToLongDateString()
其中 DB_A448D1_ilgswork.username == txtusername.Text





我尝试过:



  var  getreminders =( from  DB_A448D1_ilgswork  in  doAction.uni_projects 
其中 DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString()
其中 DB_A448D1_ilgswork.username == txtusername。文本
选择 DB_A448D1_ilgswork).ToList();

if (getreminders.Count > = 1
{
lbldue.Visible = true ;
lbldue.Text = 你有 + getreminders.Count()+ 为今天设置的提醒;
lbnoldue.Visible = false ;
}
else
{
lbnoldue.Visible = true ;
lbldue.Visible = false ;
}

解决方案

你没有说出什么样的错误。

I假设getreminders为null,因为你的查询没有给出结果。

当getreminders为null时,你无法访问Count属性。

你将得到一个空引用异常。



使用调试器看看你自己。




好​​的。红线在你的IDE中。

当然,IQueriable没有Count属性。

你应该把它转换成一个列表。



 var getreminders =(来自doAction.uni_projects中的DB_A448D1_ilgswork 
,其中DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString()
选择DB_A448D1_ilgswork) .ToList();


i have 2 where what i loking for is to have (where) (and)

where DB_A448D1_ilgswork.DueBy == DateTime.Today.ToLongDateString() 
                                where DB_A448D1_ilgswork.username == txtusername.Text



What I have tried:

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;
            }

解决方案

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();


这篇关于我不知道如何解决这个错误?计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆