读取绑定到数据库表的 vb.net 中 Checkedlistbox 的检查状态

Read check status of Checklistbox in vb.net bound to a databasetable

我可以使用存储在数据库中的数据成功填充 vb.net 中的清单框,代码如下:

 Private Sub report_enter() Handles tp_report.Enter
    Dim rep As DataTable = sqlite.SelectData("SELECT field,name,obligatory from cnf_oblfields WHERE module='report'")

    clb_obl.DataSource = rep
    clb_obl.ValueMember = "field"
    clb_obl.DisplayMember = "name"
    For i = 0 To rep.Rows.Count - 1
        clb_obl.SetItemChecked(i, sqlite.Int2Bool(rep.Rows(i).Item(2)))
    Next
End Sub

现在,用户可以选中和取消选中某些框。我想将这些参数的新状态存储回 table。我试过这段代码:

Private Sub bt_obli_save_Click(sender As Object, e As EventArgs) Handles bt_obli_save.Click
    For Each item In clb_obl.Items
        Dim row As DataRow = item.row

        MsgBox("INSERT OR REPLACE INTO cnf_oblfields ('field', 'obligatory') VALUES ('" & item.item("field").ToString & "', '" & item.item("obligatory").ToString & "')")
    Next
End Sub

我的问题是,将结果写回数据库的 SUB 返回原始数据,而不是我所做的更改。这大概是后台绑定数据table的原因?

感谢您的帮助! 卢卡斯

像这样修改checkedlistbox时必须更新数据表

Private Sub clb_obl_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles clb_obl.ItemCheck

    DirectCast(clb_obl.Items(e.Index), DataRowView)("obligatory") = e.NewValue

End Sub