string.isnullorempty(字符串)不起作用 [英] string.isnullorempty(string) is not working
本文介绍了string.isnullorempty(字符串)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题.
在数据库日期字段中包含空值或空值.
将日期字段加载到前端时,我想替换系统日期.而不是vb.net中的空字段.
尝试解决此查询时,String.isnullorempty(string)在.Net2003中不起作用.
您能解决我的问题吗?
Hi,
I have a problem.
At Database Datefield containing empty or null value.
While loading the date field to front end I want to replace system date. instead of empty field in vb.net.
And String.isnullorempty(string) is not working in .Net2003 while try to solve this query.
Can u solve my problem
推荐答案
如果从数据库中检索空值,它将是DBNull.Value
而不是null
.首先进行测试.
If you retrieve a null value from the database, it will beDBNull.Value
rather thannull
. Test for that first.
看看此链接底部给出的所有其他方法(用于IsNullOrEmpty) [ ^ ].
Have a look at all alternate methods (for IsNullOrEmpty) given towards the bottom of this link[^].
=== Version 1 (C#) ===
// Test version 1.
if (s == null || s == "")
{
Console.WriteLine("1");
}
=== Version 3 (C#) ===
// Test version 3.
if (s == null || s.Length == 0)
{
Console.WriteLine("3");
}
日期字段为空时为DBNull.不是Null或"
一个快速解决问题的方法是:String.IsNullOrEmpty(myString.toString)
或检查是否为DBNull.
The datefield is DBNull when empty. Not Null or ""
A quick solution for your problem would be: String.IsNullOrEmpty(myString.toString)
Or to check for DBNull.
这篇关于string.isnullorempty(字符串)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文