Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Database not updating" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old June 3rd, 2008, 10:04 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default Database not updating

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
Reply With Quote
Sponsored Links
  #2  
Old June 3rd, 2008, 10:13 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

I can't believe it. I've spent literally hours looking through this code and have just spotted my mistake.

I set the parameter of the table key for updating to the wrong property of the object.

Just couldn't see the wood for the trees.

Sorry guys....
Reply With Quote
  #3  
Old June 3rd, 2008, 10:13 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 947
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Start by putting a breakpoint on Public Shared Function Save and then press F5. Run the page and try saving. The debugger will popup in Visual Studio. step through each line and view the values for each property. See if they have even changed.
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

Reply With Quote
  #4  
Old June 3rd, 2008, 10:14 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 947
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Quote:
Originally Posted by richyrich View Post
I can't believe it. I've spent literally hours looking through this code and have just spotted my mistake.

I set the parameter of the table key for updating to the wrong property of the object.

Just couldn't see the wood for the trees.

Sorry guys....
You really must be more careful, rr
Reply With Quote
The Following User Says Thank You to jmurrayhead For This Useful Post:
richyrich (June 3rd, 2008)
  #5  
Old June 3rd, 2008, 10:46 AM
Wolffy's Avatar
Slaprentice of Wolves
 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 176
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Yup, the best I've found for locating an error is to post a question on the boards -- you'll spot in minutes after you hit save.
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
The Following User Says Thank You to Wolffy For This Useful Post:
richyrich (June 3rd, 2008)
  #6  
Old June 3rd, 2008, 10:52 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

Quote:
Originally Posted by Wolffy
Yup, the best I've found for locating an error is to post a question on the boards -- you'll spot in minutes after you hit save.
LOL....Yep, it's always the case, isn't it....
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Store Calculated Values (Updating Fields) sbenj69 Access Database Samples 6 May 26th, 2008 10:18 AM
Help with Updating field Rebelle Microsoft Access 5 April 1st, 2008 06:45 PM


All times are GMT -4. The time now is 09:03 AM.



Content Relevant URLs by vBSEO 3.2.0