如何保存已选中的复选框?

时间:2019-01-24 05:54:17

标签: vb.net

Dim chcboxes() As CheckBox = {CheckBox1, CheckBox2, CheckBox3}
For i As Integer = 0 To chcboxes.Length

    If (chcboxes(i).CheckState = CheckState.Checked) Then
        cmd.CommandText = "insert into array_tbl(array_id,answer) values ('" & i & "'  , '" & CheckBox1.Text & "')"
        cmd.ExecuteNonQuery()

错误是:

  

array.exe中发生了'System.IndexOutOfRangeException'类型的未处理异常

     

其他信息:索引超出了数组的范围。

1 个答案:

答案 0 :(得分:1)

For条件更改为:

For i As Integer = 0 To chcboxes.Length - 1