使用单选按钮值评估结果插入数据库

时间:2016-11-01 14:39:36

标签: database vb.net radio-button

使用vb.net在数据库中插入单选按钮的代码是什么?我试过这个,但它没有用。帮我。抱歉我的语法很差。

Dim s As Boolean

If optADD_A.Checked = True Then
    s = True
ElseIf optADD_B.Checked = True And optADD_C.Checked = True And optADD_D.Checked = True Then
    s = False
End If

If optADD_B.Checked = True Then
    s = True
ElseIf optADD_A.Checked = True And optADD_C.Checked = True And optADD_D.Checked = True Then
    s = False
End If

If optADD_C.Checked = True Then
    s = True
Else
    s = False
End If

If optADD_D.Checked = True Then
    s = True
Else
    s = False
End If

sql = "INSERT INTO tblAdd(Answer)VALUES('" & s & "')"

Dim cmd As New OledbCommand(sql,con)

cmd.ExecuteNonQuery()

1 个答案:

答案 0 :(得分:0)

我试图遵循你的逻辑。当检查C和D以及A或B中的任何一个时,答案都是正确的。还大大简化了您的代码。

Dim s As Boolean = (optADD_A.Checked OrElse optADD_B.Checked) _
                   AndAlso optADD_C.Checked _
                   AndAlso optADD_D.Checked 

sql = "INSERT INTO tblAdd(Answer) VALUES('" & s & "')"

Dim cmd As New OledbCommand(sql, con)

cmd.ExecuteNonQuery()