I have the following ASP.NET (VB) code:
strLocation = CStr(q1("LocationName")) + " " + CStr(q1("LocationAddress")) + " " + CStr(q1("LocationCity"))
由于LocationCity为空:
我遇到了“从类型 'DBNull' 转换为类型 'String' 无效”的转换错误。
有没有解决方案。
如果只有LocationCity,我可能会执行以下操作:
If IsDBNull(q1("LocationCity")) Then
strLocation = ""
Else
strLocation = CStr(q1("LocationCity"))
End If
我也尝试了以下方法:
strLocation = If(CStr(q1("LocationName")), "") + " " + If(CStr(q1("LocationAddress")), "") + " " + If(CStr(q1("LocationCity")), "")
但得到了相同的结果
在C#中,我通常会使用??,但不确定在ASP.NET VB中最好的方法是什么