Updating an Access Database using SQL in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JCMUtdfan1
    New Member
    • Mar 2013
    • 2

    #1

    Updating an Access Database using SQL in VB

    I've been trying to update my database using SQL while in VB. I've had a look at the site and used ideas that other people have given but it's still not working so I thought I'd post a question. The databse I'm using is called 'Coursework_Dat abase', the table I want to update is called 'Science_Bookin g', the record I want to update is called 'Booking' and it's a yes/no data type. I'll post the code below and I hope someone can help.
    Thanks.

    Code:
            Dim Connection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Coursework_Database.accdb")
    
            Connection.Open()
    
            Dim SQL = "UPDATE [Science_Booking] SET [Booking] = 'True' WHERE (([Booking] = False)) AND (ID = '1')"
    
    
            Dim Command As New OleDb.OleDbCommand(SQL, Connection)
            Dim Data_Writer As OleDb.OleDbDataReader = Command.ExecuteReader
    Last edited by Rabbit; Mar 15 '13, 03:56 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    When you say it's not working, what does that mean? Are you getting error messages? What are they? Is the wrong data getting updated? What's getting updated that's not supposed to? Something else?

    Comment

    • JCMUtdfan1
      New Member
      • Mar 2013
      • 2

      #3
      Sorry, I'm new to this forum and didn't know that.

      Also yeah I wasn't very clear with that, what should happen is that it should update the database like I said and open another form. However it gets to opening the form which is when the crashes and the error says 'OleDbException was undhandled' 'No value given for one or more required parameters'. Originally I thought it was a problem with my SQL but I think it's line nine that's the problem. I hope this is enough information for you to help, if you need any more just let me know.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        I don't see anything overtly wrong with the code. Have you tried running the query directly in the database to see if there's anything wrong with it? For example, I noticed you put true in quotes but false without quotes. In quotes, the value is a string, without quotes, the value is a boolean. Which one you use will depend on your database engine and table design.

        Comment

        Working...