本文整理汇总了VB.NET中System.Convert.IsDBNull方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Convert.IsDBNull方法的具体用法?VB.NET Convert.IsDBNull怎么用?VB.NET Convert.IsDBNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Convert
的用法示例。
在下文中一共展示了Convert.IsDBNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Define ADO.NET objects.
Dim conn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
' Open connection, and retrieve dataset.
conn.Open()
' Define Command object.
cmd.CommandText = "Select * From Responses"
cmd.CommandType = CommandType.Text
cmd.Connection = conn
' Retrieve data reader.
dr = cmd.ExecuteReader()
Dim fieldCount As Integer = dr.FieldCount
Dim fieldValues(fieldCount - 1) As Object
Dim headers(fieldCount - 1) As String
' Get names of fields.
For ctr As Integer = 0 To fieldCount - 1
headers(ctr) = dr.GetName(ctr)
Next
' Set up data grid.
grid.ColumnCount = fieldCount
With grid.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(grid.Font, FontStyle.Bold)
End With
With grid
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = True
For columnNumber As Integer = 0 To headers.Length - 1
.Columns(columnNumber).Name = headers(columnNumber)
Next
End With
' Get data, replace missing values with "NA", and display it.
Do While dr.Read()
dr.GetValues(fieldValues)
For fieldCounter As Integer = 0 To fieldCount - 1
If Convert.IsDBNull(fieldValues(fieldCounter)) Then
fieldValues(fieldCounter) = "NA"
End If
Next
grid.Rows.Add(fieldValues)
Loop
dr.Close()
End Sub