mysql - 使用 vb.net 窗口窗体中的复选框列表更新数据库中列的值

标签 mysql vb.net winforms checkboxlist

我有这行代码:

For i As Integer = 0 To CBL.Items.Count
    If CBL.Items(i).Selected Then
        If i = 0 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set Picture = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 1 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set BCertificate = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 2 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set DTest = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 3 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set XRay = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 4 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set MCertificate = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 5 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set BClearance = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 6 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set PNClearance = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If
        If i = 7 Then
            myr.Close()
            mycom.CommandText = "Update tbl_employee set DLicense = 'Ok' where LastName='" & txtLastName.Text & "',FirstName='" & txtFirstName.Text & "' ,MiddleName='" & txtMiddleName.Text & "' "
            myr = mycom.ExecuteReader
            myr.Close()
        End If

    End If
Next

我遇到错误:未找到类型“String”上的公共(public)成员“Selected”..

我在表单加载上有以下代码:

CBL.Items.Add("Picture")
CBL.Items.Add("Birth Certificate")
CBL.Items.Add("Drug Test")
CBL.Items.Add("X-Ray")
CBL.Items.Add("Medical Certificate")
CBL.Items.Add("Barangay Clearance")
CBL.Items.Add("Police/NBI Clearance")
CBL.Items.Add("Drivers License for Drivers")

我只是这样:“我为所有项目创建了一个循环,如果选中该复选框,则该项目的索引再次传递到 if 条件,其中该项目的索引等于 sql 语句。 请任何帮助..

最佳答案

我假设 CBL 是一个 CheckedListBox。如果是这样,CBL.Items(i) 就没有 Selected 属性。您可以改用 CheckState 属性。

关于mysql - 使用 vb.net 窗口窗体中的复选框列表更新数据库中列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27265603/

相关文章:

c# - excel Vb.Net 中的数字格式

javascript - 停止传播使用 ASP.Net 中的属性定义的 JavaScript 事件

vb.net - 如何在顶部制作表格

Mysql - 如何在每行的第二个字符后插入一个点?

.net - 为什么是 String.ToString()?

c# - PopupContainerEdit with XtraTreeList 作为下拉演示

c# - 关于 C# 中的 string.Intern

php - Doctrine 查询生成器给出了错误的结果

mysql - 使用 Ruby on Rails 应用程序中的单选按钮在 MySQL 表中创建记录

php - 如何根据取件日期和归还日期进行搜索?