Customer customer = new Customer(); customer.Name = "John Doe"; customer.Address = "123 Main St"; customer.Email = "[email protected]";
using System.Data.SqlClient; // Assuming we have a SqlConnection object named "connection" SqlCommand command = new SqlCommand("SELECT * FROM Customers", connection); SqlDataReader reader = command.ExecuteReader(); Listcustomers = new List (); while (reader.Read()) { Customer customer = new Customer(); customer.Name = reader["Name"].ToString(); customer.Address = reader["Address"].ToString(); customer.Email = reader["Email"].ToString(); customers.Add(customer); }
// Assuming we have a Customer object named "customer" and a SqlConnection object named "connection" SqlCommand command = new SqlCommand("UPDATE Customers SET Address = @Address, Email = @Email WHERE Name = @Name", connection); command.Parameters.AddWithValue("@Address", customer.Address); command.Parameters.AddWithValue("@Email", customer.Email); command.Parameters.AddWithValue("@Name", customer.Name); command.ExecuteNonQuery();These examples could be part of a larger business application package library, such as a customer relationship management (CRM) system or an e-commerce platform.