March 2019
Intermediate to advanced
336 pages
9h 9m
English
The update operation is as follows. The UpdateCustomer method takes the Customer parameter and creates a prepared statement for the UPDATE statement. The statement is used to update a customer row in the table:
// Update Customer method with parameter customerfunc UpdateCustomer(customer Customer){ var database *sql.DB database= GetConnection() var error error var update *sql.Stmt update,error = database.Prepare("UPDATE CUSTOMER SET CustomerName=?, SSN=? WHERE CustomerId=?") if error != nil { panic(error.Error()) } update.Exec(customer.CustomerName,customer.SSN,customer.CustomerId)defer database.Close()}// main methodfunc main() { var customers []Customer customers = GetCustomers() fmt.Println("Before Update",customers) ...
Read now
Unlock full access