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 Try 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 sqlconn.Open() 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.ExecuteNonQuery() '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) 'sqlquery.ExecuteNonQuery() sqlconn.Close() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Last edited by a moderator: