Results 1 to 4 of 4

Thread: SQL Update Query issue

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Aug 2018

    Question SQL Update Query issue

    Hey guys, so I have a bit of problem regarding my current coding within my project, this issue being that I am struggling to get this code to run when trying to update an already existing record within an Access database, any assistance given would be highly appreciated
    Private Sub btn_Add_Click(sender As Object, e As EventArgs) Handles btn_Add.Click
    Dim sqlconn As New OleDb.OleDbConnection
    Dim sqlquery As New OleDb.OleDbCommand
    Dim connString As String
    connString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='E:\A-Level Computer Science\Project\BritishAirwaysDatabase.mdb';Persist Security Info=False;")
    sqlconn.ConnectionString = connString
    sqlquery.Connection = sqlconn
    sqlquery.CommandText = "INSERT INTO Bookings(BookingID, Firstname, Surname, FlightNo, Destination, Cost)VALUES(@BookingID, @Firstname, @Surname, @FlightNo, @Destination, @Cost)"
    sqlquery.Parameters.AddWithValue("@BookingID", txt_SearchID.Text)
    sqlquery.Parameters.AddWithValue("@Firstname", txt_Firstname.Text)
    sqlquery.Parameters.AddWithValue("@Surname", txt_Surname.Text)
    sqlquery.Parameters.AddWithValue("@FlightNo", txt_FlightNo.Text)
    sqlquery.Parameters.AddWithValue("@Destination", txt_Destination.Text)
    sqlquery.Parameters.AddWithValue("@Cost", txt_Cost.Text)

    'sqlquery.CommandText = "UPDATE Bookings" &
    ' "SET Firstname = @Firstname" &
    ' "Surname = @Surname" &
    ' "FlightNo = @FlightNo" &
    ' "Destination = @Destination" &
    '"Cost = @Cost" &
    '"Where BookingID = @BookingID"
    'sqlquery.Parameters.AddWithValue("@Firstname", txt_Firstname)
    'sqlquery.Parameters.AddWithValue("@Surname", txt_Surname)
    'sqlquery.Parameters.AddWithValue("@FlightNo", txt_FlightNo)
    'sqlquery.Parameters.AddWithValue("@Destination", txt_Destination)
    'sqlquery.Parameters.AddWithValue("@Cost", txt_Cost)
    Catch ex As Exception
    End Try
    End Sub
    Last edited by JuggaloBrotha; 08-15-2018 at 10:42 AM. Reason: Added xcode tag

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Lansing, MI; USA
    First thing I see is you say you want to do an update query but your code shows an insert query.
    It looks like you have the start of code for an update query, but it's commented out so I don't know if that's where you need help or not.

    Can you please specify.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Aug 2018
    Hey thanks for taking the time to look through it, yeah the commented out part is just for the sake of running the program without any issues because as of right now that part of the code isn't fully working, that's the only reasoning behind that.

  4. #4
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Sydney, Australia
    I don't really get it. You have an 'Add' button that executes an INSERT statement. Why would you think that that would update an existing record? You have code commented out that looks like it would at least go some ways to doing what you want but you say that that's just for running the program without issues. Isn;t running the program without issues what you want? How about you don;t post code here that we all know has nothing to do with what you're trying to achieve and show us the code that you have tried to write to do what you want? Once we see what you've actually done then we can see what's wrong with it and help you fix that. Showing us code that inserts a new record is useless if you want help with updating an existing record. Show us the code that you think should/could do that.

Similar Threads

  1. Question VB/SQL Select Query syntax issue!
    By rgouette in forum Database General Discussion
    Replies: 2
    Last Post: 06-17-2015, 1:14 PM
  2. Question Issue passing Now as OleDbParameter in Update Query
    By VBobCat in forum MS Access
    Replies: 7
    Last Post: 09-17-2012, 9:21 AM
  3. Interesting SQL type Query and Issue
    By jasen in forum Database General Discussion
    Replies: 0
    Last Post: 07-29-2011, 2:47 PM
  4. Update Sql Query ?
    By AukI in forum Database General Discussion
    Replies: 2
    Last Post: 12-10-2010, 1:48 AM
  5. Using Update query to sql
    By amitrishi26 in forum Database General Discussion
    Replies: 0
    Last Post: 05-04-2007, 4:49 AM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts