[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

ASP.Net Access Update not working

I have an access update query that was working last week and now when I try to run it nothing happens. I do not get an error message but the database is not getting updated. I run the same query in access and it works fine. Any Ideas why its not working now?
Dim con As New System.Data.OleDb.OleDbConnection
        Dim myPath As String
 
        myPath = Server.MapPath("App_Data/Visions_DB.mdb")
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
 
        Dim updCmd As New System.Data.OleDb.OleDbCommand
 
        updCmd.CommandText = "Update Data SET Present_Method=?,Proposed_Method=?,Status=?,Facilitator=?,Validator=?,Notes=?,Area=?,ValDate=? WHERE Vis_Num=?"
 
        '## Inserts values from form into Update command string ##
        updCmd.Parameters.AddWithValue("Present_Method", txtPresent.Text)
        updCmd.Parameters.AddWithValue("Proposed_Method", txtProposed.Text)
        updCmd.Parameters.AddWithValue("Status", ddstatus.SelectedValue)
        updCmd.Parameters.AddWithValue("Facilitator", ddFacilitator.SelectedValue)
        updCmd.Parameters.AddWithValue("Validator", txtImplement.Text)
        updCmd.Parameters.AddWithValue("Notes", txtNotes.Text)
        updCmd.Parameters.AddWithValue("ValDate", StartDatetxt.Text)
        updCmd.Parameters.AddWithValue("Vis_Num", txtVisNum.Text)
        updCmd.Parameters.AddWithValue("Area", ddArea.SelectedValue)
 
        updCmd.Connection = con
        con.Open()
        updCmd.ExecuteNonQuery()
        con.Close()

Open in new window

0
ITHelper80
Asked:
ITHelper80
  • 2
1 Solution
 
ITHelper80Author Commented:
I added some error checking....there are no exceptions and my return value from executenonquery is 0
0
 
gandalf97Commented:
When I troubleshoot my own apps, the first question I always ask is "What Changed?"  Even if your first instinct is to say "Nothing changed.", something had to.  Figuring out what isn't always easy but it will help you figure things out.

Are you familiar with setting breakpoints and using the debugger?  Either your CommandText string does not contain what you think it does or one/more of your parameters are messed up.  Also check to make sure you aren't trying to insert a record where the primary key is duplicated.

Does this help?

Regards,
Gandalf
0
 
oobaylyCommented:
It looks like the ordering of your parameters has changed. As the parameters aren't named order is important:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.parameters.aspx
        updCmd.Parameters.AddWithValue("Present_Method", txtPresent.Text)
        updCmd.Parameters.AddWithValue("Proposed_Method", txtProposed.Text)
        updCmd.Parameters.AddWithValue("Status", ddstatus.SelectedValue)
        updCmd.Parameters.AddWithValue("Facilitator", ddFacilitator.SelectedValue)
        updCmd.Parameters.AddWithValue("Validator", txtImplement.Text)
        updCmd.Parameters.AddWithValue("Notes", txtNotes.Text)
        updCmd.Parameters.AddWithValue("Area", ddArea.SelectedValue)
        updCmd.Parameters.AddWithValue("ValDate", StartDatetxt.Text)
        updCmd.Parameters.AddWithValue("Vis_Num", txtVisNum.Text)

Open in new window

0
 
ITHelper80Author Commented:
Thaks oobayly

That was the problem....
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now