我有一个表有一个日期时间列 列可以有NULL值
I have a table with a DateTime column the column can have NULL values
现在我连接到数据库使用ODBC连接,并获得价值成.NET / C#中的数据表。
Now I connect to the database using an ODBC connection and get the value into a DataTable in .net / c#.
我能够通过去检查它是否为NULL
I am able to check it for NULL by going
if(String.IsNullOrEmpty(table.rows[0][0].ToString())
{
//Whatever I want to do
}
时String.IsNullOrEmpty以检查空值的正确方法。
Is String.IsNullOrEmpty the correct way to check for null values.
使用的DBNull.Value。等于中的对象上,而不将其转换成字符串。
Use DBNull.Value.Equals on the object without converting it to a string.
下面是一个例子:
if (! DBNull.Value.Equals(row[fieldName]))
{
//not null
}
else
{
//null
}
上一篇:如何刷新ObjectContext的高速缓存从数据库?高速缓存、数据库、ObjectContext
下一篇:非序列化和Xml.Serialization.XmlIgnore之间的区别?区别、序列化、Serialization、Xml