如何用VB.NET判断数据库的BIT值的0和空?
在中我用一个布尔值读取数据库的bit类型值,但是有个问题是,我想区分bit值为0和为空,也就是判断3种状态。经过测试,VB.ENT的布尔值类型会把bit的0和空值都理解为false
'还是拿你的数据做例子 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connStr As String = "SERVER=.;UID=sa;PWD=;DATABASE=ceshi" Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(connStr) Dim rs As New SqlClient.SqlDataAdapter Dim mydata As New DataSet() Dim cmd As SqlCommand = conn.CreateCommand Dim sql As String = "select * from [admin] where [kd_xsdh]='user'" = sql conn.Open() rs.SelectCommand = cmd rs.Fill(mydata, "1") Try Select Case mydata.Tables(0).Rows(0)("kd_zuofei").ToString Case "True" MsgBox("bit值为 1") Case "False" MsgBox("bit值为 0") Case Else MsgBox(" bit值为空值") End Select conn.Close() Catch ex As Exception MsgBox("数据库中没有此记录") End Try End Sub