ASP.NET VB – 从类型’DBNull’到类型’String’的转换无效
发布时间:2020-12-16 03:58:44 所属栏目:asp.Net 来源:网络整理
导读:我有以下ASP.NET(VB)代码: strLocation = CStr(q1("LocationName")) + " " + CStr(q1("LocationAddress")) + " " + CStr(q1("LocationCity")) 由于LocationCity为null: 我从类型’DBNull’到类型’String’的转换无效. 有没有办法来解决这个问题. 如果它只
我有以下ASP.NET(VB)代码:
strLocation = CStr(q1("LocationName")) + " " + CStr(q1("LocationAddress")) + " " + CStr(q1("LocationCity")) 由于LocationCity为null: 我从类型’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中的最佳方法 解决方法
相当于C#??在VB.NET中是
IF Operator
strLocation = If(IsDBNull(q1("LocationCity")),"",CStr(q1("LocationCity"))) 不要使用IIF Function,因为它已被弃用,不支持短路且不是类型安全的. 有关相关信息,请参阅Is there a VB.NET equivalent for C#’s ?? operator? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – MVC3 / Razor添加控制器“Get-PrimaryKey
- asp.net-mvc-3 – Value Injecter是否会映射集合属性?
- asp.net – Autofac OWIN TestServer和HttpContext
- asp.net – 用于bower.json文件的Visual Studio 2015 RC上的
- asp.net – asp mvc http以对象作为参数获取动作
- asp.net-mvc – 在TDD和DDD中,你如何处理假货中的只读属性?
- ASP.NET Core 认证与授权[7]:动态授权
- asp.net – 在页面生命周期内保持数据库连接打开是否可以接
- entity-framework – 使用Entity框架核心生成和访问存储过程
- asp.net-mvc – MVC的理由?
推荐文章
站长推荐
热点阅读