开发者

boolean from a form(VB.net) insert into a SQl DB

How,in VB.net 2010, a checked checkbox(b开发者_JAVA技巧oolean) from a form to insert as a string in an SQL database like a character "T" or "F"


Dim value as string = "F"
If checkbox.checked then
    value = "T"
end if

Then use value in your database operation.


Here's a concise way of putting it:

Dim theStringToUse as string = iif(theCheckbox.checked, "T", "F").ToString()

And in case this isn't clear, here's what you do with it:

' assume conn = an open SqlConnection
Dim cmd as new SqlCommand("Insert into TableA (theStringColumn) " & _ 
    "values (@theStringValue)", conn)

cmd.Parameters.AddWithValue("@theStringValue", theStringToUse)

cmd.ExecuteNonQuery()


When you first dim value the string should equal String.Empty so you can insert an empty string if the condition is false. Then in your if statement, value should equal whatever you want the true condition to equal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜