[英]“Value cannot be null.\r\nParameter name: text”
I have a method (Win App C#) to fill DataGridView
as below and used that in my TxB_ProitirySearch_TextChanged
event:我有一个方法(Win App C#)来填充
DataGridView
如下,并在我的TxB_ProitirySearch_TextChanged
事件中使用它:
void PrioFillGrid(bool IsSearching= false)
{
if (IsSearching)
{
var ddd = from p in db.PDP_Priorities
where p.PriorityTitle.Contains(aski.Change(TxB_ProitirySearch.Text))
orderby p.ID descending
select new { p.ID, Title = p.PriorityTitle };
if (ddd.Count() > 0) // Solution1
{
DG_Priority.DataSource = ddd;
}
if (ddd != null) // Solution2
{
DG_Priority.DataSource = ddd;
}
else
{
DG_Priority.DataSource = from p in db.PDP_Priorities
orderby p.ID descending
select new { p.ID, Title = p.PriorityTitle };
}
}
else
{
DG_Priority.DataSource = from p in db.PDP_Priorities
orderby p.ID descending
select new { p.ID, Title = p.PriorityTitle };
}
}
When I type a character, it's searching very well and updating data in gridview, but pressing backspace to clear the textbox and start a new search raises this exception:当我输入一个字符时,它会在 gridview 中很好地搜索并更新数据,但是按退格键清除文本框并开始新的搜索会引发此异常:
An unhandled exception of type 'System.ArgumentNullException' occurred in System.Data.Linq.dll"
System.Data.Linq.dll 中发生类型为“System.ArgumentNullException”的未处理异常”
Value cannot be null.
值不能为空。 Parameter name: text
参数名称:文本
(Comment: aski.Change(TxB_ProitirySearch.Text)
is a class to prevent unwanted characters from being saved in the database) (注释:
aski.Change(TxB_ProitirySearch.Text)
是一个防止不需要的字符保存在数据库中的类)
I'm wondering why both solution1 and 2 won't help.我想知道为什么解决方案 1 和 2 都无济于事。
Could anybody please help me?有人可以帮我吗?
Thanks in advance.提前致谢。
Great thanks to all of you, masters.非常感谢你们,大师们。 changing "PriorityTitle.Contains to PriorityTitle?.Contains?"
改变“PriorityTitle.Contains 到 PriorityTitle?.Contains?” didn't work for me, but using others guide, I changed the class, aski.change() as below:
对我不起作用,但使用其他指南,我更改了类, aski.change() 如下:
public string Change(string k)
{
if (k==string.Empty)
{
return null;
}
else
{
//some codes...
return str;
}
}
and then changed my "PrioFillGrid()" method as below:然后更改我的“PrioFillGrid()”方法如下:
void PrioFillGrid(bool IsSearching= false)
{
if (aski.Change(TxB_ProitirySearch.Text) == null)
{
DG_Priority.DataSource = from p in db.PDP_Priorities
orderby p.ID descending
select new { p.ID, Title = p.PriorityTitle };
}
else if (IsSearching && aski.Change(TxB_ProitirySearch.Text) != null)
{
var ddd= from p in db.PDP_Priorities
where p.PriorityTitle.Contains(aski.Change(TxB_ProitirySearch.Text))
orderby p.ID descending
select new { p.ID, Title = p.PriorityTitle };
DG_Priority.DataSource = ddd;
}
else
{
DG_Priority.DataSource = from p in db.PDP_Priorities
orderby p.ID descending
select new { p.ID, Title = p.PriorityTitle };
}
}
and now is working well.现在运行良好。 Thanks again every body.
再次感谢每一个身体。
对我来说,问题是 DI 机制创建了UrlHelper
实例,这导致该实例的所有属性都为 null,包括routeCollection
和requestContext
,通过将 UrlHelper 实例直接传递给需要它的方法来解决。
Solution 1 and 2 do not help because the exception is thrown prior.解决方案 1 和 2 没有帮助,因为异常是事先抛出的。
I am guessing in the aski.Change() method.我在 aski.Change() 方法中猜测。
Try尝试
if (IsSearching && !string.IsNullOrEmpty(TxB_ProitirySearch.Text)) if (IsSearching && !string.IsNullOrEmpty(TxB_ProitirySearch.Text))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.