I am probably missing something incredibly obvious, but I've compared this code to something else I wrote that does the exact same thing and don't see any reason why one works and one doesn't. (Maybe I just need more coffee)
I've got a form with 2 list boxes, one box has all of the modules required by a user, the other box has every other module. Pretty simple. There's 2 buttons to move selected items between the boxes which is where I run in to issues. Nothing throws an error but nothing happens when the buttons are pressed, the page posts back but the modules are never moved between the boxes.
One button calls AddRem with "Add" the other with "Rem"
Code:
Private Sub AddRem(ByVal action As String)
Dim cmdUpdate As OleDbCommand
Dim strSQL As String
If action = "Add" Then
Try
If Conn.State = ConnectionState.Closed Then Conn.Open()
For Each li As ListItem In lstNotReqd.Items
If li.Selected Then
strSQL = "Insert INTO trainingrecords (employee, moduleid, firstroundrequired) Values (" & Request.QueryString("empID") & ", " & li.Value & ", true)"
cmdUpdate = New OleDbCommand(strSQL, Conn)
cmdUpdate.ExecuteNonQuery()
End If
Next
Catch ex As Exception
txtEmpName.Text = ex.ToString
Finally
Conn.Close()
End Try
Else
Try
If Conn.State = ConnectionState.Closed Then Conn.Open()
For Each li As ListItem In lstReqd.Items
If li.Selected Then
strSQL = "Delete from trainingrecords where employee = " & Request.QueryString("EmpID") & " and moduleid = " & li.Value _
& " and createdbydept <> 2"
cmdUpdate = New OleDbCommand(strSQL, Conn)
cmdUpdate.ExecuteNonQuery()
End If
Next
Catch ex As Exception
txtEmpName.Text = ex.ToString
Finally
Conn.Close()
End Try
End If
GetRecs()
End Sub
Like I said the try catch blocks there never actually throw an error which is what's confusing me, and the values are never inserted into the database. The reason records cannot be deleted if createdbydept = 2 is because those are mandatory modules created by HR, HR has a seperate admin program they can use to add/remove those records, this one is for general purpose users.
The list boxes are populated through this sub:
Code:
Private Sub GetRecs()
Dim rdr As OleDbDataReader
Dim li As New ListItem
Dim cmd As New OleDbCommand("select Modules.ModuleName, TrainingRecords.FirstRoundRequired, " _
& " Modules.Moduleid FROM TrainingRecords inner JOIN Modules ON TrainingRecords.ModuleID = Modules.ModuleID WHERE " _
& " TrainingRecords.Employee = " & Request.QueryString("EmpID") & " order by modules.modulename", Conn)
Try
If Conn.State = ConnectionState.Closed Then Conn.Open()
rdr = cmd.ExecuteReader
lstReqd.DataSource = rdr
lstReqd.DataTextField = "modulename"
lstReqd.DataValueField = "moduleid"
lstReqd.DataBind()
rdr.Close()
cmd.CommandText = "Select modulename, moduleid from modules where moduleid not in (select moduleid " _
& " FROM TrainingRecords WHERE Employee = " _
& Request.QueryString("EmpID") & ") order by modulename"
rdr = cmd.ExecuteReader
lstNotReqd.DataSource = rdr
lstNotReqd.DataTextField = "modulename"
lstNotReqd.DataValueField = "moduleid"
lstNotReqd.DataBind()
Catch ex As Exception
txtEmpName.Text = ex.ToString
End Try
End Sub
Like I said this is probably something glaringly obvious that I've just overlooked and can't find, but any input would be appreciated.
Edit:
It actually looks like the li items in AddRem aren't retaining their selected state when they're created.. hmm