2014-12-03 79 views
0

我有這段代碼行數:更新值形成

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 

我遇到的錯誤:公共部件類型「選擇」「字符串」未找到..

我對形式加載此代碼:

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") 

我只是這樣的:「我創造了所有項目的循環,如果複選框被選中,那麼該項目的索引再次通過到一個如果條件的地方該項目的索引等於sql語句。 請任何幫助..

回答

0

我假設CBL是一個CheckedListBox。如果是這樣,CBL.Items(i)沒有Selected屬性。您可以改用CheckState屬性。

+0

我可以用這一個呢?如果CBL.SelectedItems(i)然後 – 2014-12-03 07:21:17

+0

即使我使用'CBL.SelectedItems(i)'我仍然收到和錯誤'我得到這一個轉換從字符串「X射線」類型'布爾'是無效的。 – 2014-12-03 07:34:19

0

試試這個for循環:

For i As Integer = 0 To CBL.Items.Count - 1 
    If CBL.GetItemChecked(i) = True Then 

     //TODO YOU CODE 
     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