如何插入位数据类型列值

时间:2014-01-31 05:01:21

标签: vb.net

我有一个下拉列表框,内容为'是'并且没有'。 我把这个值插入到数据库表中,列的数据类型有点怎样才能将这个值插入到vb.net

cmd.CommandText = "INSERT INTO application_main(obligations_is) VALUES( '" + convertBit(dropdownlist1.text) + "' )"

cmd.ExecuteNonQuery()

      Public Function convertBit(ByVal dropdownlist As String)
    Dim value As Integer


    If dropdownlist = "Yes" Then
        value = 1
    Else
        value = 0
    End If

    Return value
End Function

2 个答案:

答案 0 :(得分:0)

插入BIT列时使用ISNULL功能

cmd.CommandText = "INSERT INTO application_main(obligations_is) VALUES( ISNULL('" + convetbit() + "',0) )"

cmd.ExecuteNonQuery()

功能应该是这样的

Public Function convertBit(ByVal dropdownlist As String) AS Boolean
    Dim value As Boolean = Flase
    If dropdownlist = "Yes" Then
        value = 1
    Else
        value = 0
    End If
        Return value
End Function

答案 1 :(得分:0)

这样做:

cmd.CommandText = "INSERT INTO application_main(obligations_is) VALUES(@value)"
cmd.Parameters.AddWithValue("@value", If ((dropdownlist1.text = "Yes"), True, False))
cmd.ExecuteNonQuery()