我想将数据库中的所有内容显示到asp.net。但我的一些值(value)是空的,有些则不是。当我加载到 null 页面时,它会导致错误。我可以知道如何解决这个问题吗?我的意思是显示数据库中的所有内容,不在乎它是 NULL 还是有内容。
SELECT m.PersonID, m.Picture,m.PersonName, t.title, t.Fileupload, t.contentBody, t.dateInserted FROM person m, thread t WHERE m.PersonID = t.PersonID AND t.threadID = @TID
我的数据库中的 t.FileUpload 某些行为空,有些包含包含。错误是
system.invalidcastexception unable to cast object of type 'system.dbnull' to type 'system.string'
最佳答案
使用标准 SQL 合并函数。
SELECT a.PersonID,
Coalesce (a.Picture, othercolumn, anothercolumn, 'if all are null') as Picture
from tableA a
它将返回第一个非空值。
或者只是简单地:
Coalesce (a.Picture, '') as Picture
这将防止无效广播异常
关于c# - 在asp.net中显示数据库中的Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125434/