2014-01-31 54 views
2

我有一個下拉列表框,它的內容是'是'和'否'。 我插入這個值到列的數據庫表中的數據類型是有點我怎麼可以插入該數值到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 

回答

0

使用ISNULL功能,同時插入位列

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

cmd.ExecuteNonQuery() 

而且fucnction應像這樣

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 
0

做這樣的:

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