Question insert multiple checkboxlist value

lyealain

New member
Joined
Mar 8, 2008
Messages
4
Programming Experience
Beginner
may i know how to reduce this junk of code ..

i have those chkSubjects , chkKet .. as different checkboxlist

my situation here is : i have multiple checkboxlist , when i want to press save button, i would like to insert those selected = true value into database
VB.NET:
1    
2                For iLoop = 0 To chkSubjects.Items.Count - 1
3                    If chkSubjects.Items(iLoop).Selected = True Then
4                        Dim qryInsertSubjects As String = "INSERT INTO Subject (ID, Subject) VALUES ('" & strStudentID & "','" & chkSubjects.Items(iLoop).Value & "')"
5                        Database.ODBCExecute(qryInsertSubjects, conn)
6                    End If
7                Next
8                For iLoop = 0 To chkKET.Items.Count - 1
9                    If chkKET.Items(iLoop).Selected = True Then
10                       Dim qryInsertSubjects As String = "INSERT INTO Subject (ID, Subject) VALUES ('" & strStudentID & "','" & chkKET.Items(iLoop).Value & "')"
11                       Database.ODBCExecute(qryInsertSubjects, conn)
12                   End If
13               Next
14               For iLoop = 0 To chkPET.Items.Count - 1
15                   If chkPET.Items(iLoop).Selected = True Then
16                       Dim qryInsertSubjects As String = "INSERT INTO Subject (ID, Subject) VALUES ('" & strStudentID & "','" & chkPET.Items(iLoop).Value & "')"
17                       Database.ODBCExecute(qryInsertSubjects, conn)
18                   End If
19               Next
20               For iLoop = 0 To chkPREFCE.Items.Count - 1
21                   If chkPREFCE.Items(iLoop).Selected = True Then
22                       Dim qryInsertSubjects As String = "INSERT INTO Subject (ID, Subject) VALUES ('" & strStudentID & "','" & chkPREFCE.Items(iLoop).Value & "')"
23                       Database.ODBCExecute(qryInsertSubjects, conn)
24                   End If
25               Next
26               For iLoop = 0 To chkFCE.Items.Count - 1
27                   If chkFCE.Items(iLoop).Selected = True Then
28                       Dim qryInsertSubjects As String = "INSERT INTO Subject (ID, Subject) VALUES ('" & strStudentID & "','" & chkFCE.Items(iLoop).Value & "')"
29                       Database.ODBCExecute(qryInsertSubjects, conn)
30                   End If
31               Next
32               For iLoop = 0 To chkCAE.Items.Count - 1
33                   If chkCAE.Items(iLoop).Selected = True Then
34                       Dim qryInsertSubjects As String = "INSERT INTO Subject (ID, Subject) VALUES ('" & strStudentID & "','" & chkCAE.Items(iLoop).Value & "')"
35                       Database.ODBCExecute(qryInsertSubjects, conn)
36                   End If
37               Next
 

Latest posts

Back
Top