I've spent hours trying to work out why this is happening, but am at a complete dead-end.
In my code behind content page, I check all form elements against the current value. If it's changed, I do some validation and then if it passes, I update the value of the property in the object and add to an arraylist to tell my update function to update this value.
If there are any values in this arraylist, it calls an update function in my BLL, passing the object and the fieldlist.
Code:
If Not fieldlist.Count = 0 Then
If String.IsNullOrEmpty(TaskDetails.page_error) Then
If TaskBLL.SaveTask(TaskDetails, fieldlist, Master.UserDetails.pcuser) Then
update_error.Visible = True
If source = "complete_but" Then
update_error.Text = Master.SiteDetails.correct_box_start("n") & "The task has been completed<br />" & fieldlist.ToString & Master.SiteDetails.box_end
Else
update_error.Text = Master.SiteDetails.correct_box_start("n") & "The task has been updated" & Master.SiteDetails.box_end
End If
ftb_mess.Text = ""
build_notes()
build_userlist()
build_properties()
build_complete()
Master.build_left_menu()
Else
update_error.Visible = True
update_error.Text = Master.SiteDetails.error_box_start("n") & "An error occurred whilst updating the task details<br />" & TaskDetails.page_error & Master.SiteDetails.box_end
End If
Else
update_error.Visible = True
update_error.Text = Master.SiteDetails.error_box_start("n") & "An error occurred whilst updating the task details<br />" & TaskDetails.page_error & Master.SiteDetails.box_end
End If
Else
update_error.Visible = True
update_error.Text = Master.SiteDetails.correct_box_start("n") & "The task details have been updated" & Master.SiteDetails.box_end
End If
My BLL calls a function in the DAL that passes the task object, the fieldlist and the userref. the DAL function then should update the DB.
DAL
Code:
Public Shared Function Save(ByVal task As TaskBOL, ByVal fieldlist As ArrayList, ByVal pcuser As Integer) As Boolean
If Not fieldlist.Count = 0 Then
Dim strsql As New StringBuilder
Dim ex_strsql As New StringBuilder
If fieldlist.Contains("visitorref") Then strsql.Append(",visitorref=?visitorref")
If fieldlist.Contains("introref") Then strsql.Append(",introref=?introref")
If fieldlist.Contains("category") Then strsql.Append(",category=?category")
If fieldlist.Contains("title") Then strsql.Append(",title=?title")
If fieldlist.Contains("datedue") Then strsql.Append(",datedue=?datedue")
If fieldlist.Contains("timespent") Then strsql.Append(",timespent=?timespent")
If fieldlist.Contains("complete") Then strsql.Append(",complete='y',completedby=?userref,datecompleted=CURDATE(),filepath=(NULL)")
Dim conn As New MySqlConnection(ConnDAL.connString)
Dim mycommand As New MySqlCommand
Try
ex_strsql.Append("UPDATE user_tasks SET last_updated=NOW(),updatedby=?userref" & strsql.ToString & " WHERE todoref=?todoref;")
'ex_strsql.Append("UPDATE user_tasks_links SET last_viewed=NOW() WHERE todoref=?todoref AND userref=?userref;")
mycommand.Connection = conn
mycommand.CommandText = ex_strsql.ToString
conn.Open()
mycommand.Parameters.AddWithValue("todoref", task.visitorref)
mycommand.Parameters.AddWithValue("userref", pcuser)
If fieldlist.Contains("visitorref") Then mycommand.Parameters.AddWithValue("visitorref", task.visitorref)
If fieldlist.Contains("introref") Then mycommand.Parameters.AddWithValue("introref", task.introref)
If fieldlist.Contains("category") Then mycommand.Parameters.AddWithValue("category", task.category)
If fieldlist.Contains("title") Then mycommand.Parameters.AddWithValue("title", task.title)
If fieldlist.Contains("datedue") Then
If Not IsNothing(task.datedue) Then
mycommand.Parameters.AddWithValue("datedue", Format(task.datedue, "yyyy/MM/dd"))
Else
mycommand.Parameters.AddWithValue("datedue", DBNull.Value)
End If
End If
If fieldlist.Contains("timespent") Then mycommand.Parameters.AddWithValue("timespent", task.timespent)
mycommand.ExecuteNonQuery()
Catch ex As MySqlException
task.page_error = ex.Message.ToString
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
If String.IsNullOrEmpty(task.page_error) Then
Return True
Else
Return False
End If
end function
For some reason the values in the db aren't being updated. If I change the category, for example, the page tells me the details have updated, but if I reload the page, nothing's changed.
I've debugged the code passing values to the screen and as far as I can tell, it runs with no problems. I get no errors, but the details don't update.
I use the same syntax in other functions and they work fine. I'm just at a complete loss as to why this won't work.
Does anyone have any idea what the problem might be?
Thanks