static void Main(string[] args) { Customer eklenecek = new Customer(); eklenecek.Country = "Türkiye"; eklenecek.DateOfBorn = Convert.ToDateTime("1990-03-28"); eklenecek.FirstName = "Hasan"; eklenecek.LastName = "Mehmet"; int customerId = eklenecek.AddCustomer(); Customer guncellenecek = new Customer(); guncellenecek.Id = customerId; guncellenecek.Country = "Türkiye"; guncellenecek.DateOfBorn = Convert.ToDateTime("1989-03-28"); guncellenecek.FirstName = "Hasan"; guncellenecek.LastName = "Mehmet"; guncellenecek.UpdateCustomer(); Customer silinecek = new Customer(); silinecek.Id = customerId; silinecek.RemoveCustomer(); Customer businessOperation = new Customer(); int customerCount = businessOperation.GetCustomerCount(); List<Customer> after1990 = businessOperation.GetCustomerBornAfterDate(new DateTime(1990,01,01)); }
public List<Customer> GetCustomerBornAfterDate(DateTime datetime) { List<Customer> results = null; using (SqlConnection conn = new SqlConnection(GetConnectionString())) { SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = conn; sqlCmd.CommandText = selectAfterDate; sqlCmd.Parameters.Add(new SqlParameter("DateOfBorn", datetime)); conn.Open(); SqlDataReader reader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) results = new List<Customer>(); while (reader.Read()) { Customer cust = new Customer(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetDateTime(3), reader.GetString(4)); results.Add(cust); } } return results; }
public Customer GetCustomerbyId() { Customer cust = null; using (SqlConnection conn = new SqlConnection(GetConnectionString())) { SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = conn; sqlCmd.CommandText = selectByIdStatement; sqlCmd.Parameters.Add(new SqlParameter("Id", Id)); conn.Open(); SqlDataReader reader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { cust = new Customer(); cust.Id = reader.GetInt32(0); cust.FirstName = reader.GetString(1); cust.LastName = reader.GetString(2); cust.DateOfBorn = reader.GetDateTime(3); cust.Country = reader.GetString(4); } } return cust; }