avoid checking for DataRow.IsDBNull on each column?

前端 未结 4 1847
无人及你
无人及你 2021-01-19 07:46

My code is 2x longer than it would be if I could automatically set IsDBNull to \"\" or simply roll over it without an error.

This is my cod

4条回答
  •  情歌与酒
    2021-01-19 08:14

    Dataset Extensions give you a clean way of doing and it's also strongly typed. The type must match the column type in the database though. If the database column can be null, then use a nullable type like below. The null values become Nothing for the returned nullable type.

    For Each rs As DataRow In sqlDataset.Tables(0).Rows
    
        'If string, you can use this. Null becomes nothing for the string.
        Response.Write(rs.field(of String)("column"))
    
        'if it's another type
        Response.Write(rs.field(of Integer?)("column"))
    
    
    Next
    

提交回复
热议问题