public override CustomerList GetCustomer(string vipCode) { SqlDatabase database = new SqlDatabase(ConnectionString); DbCommand command = database.GetStoredProcCommand("rmSP_WSPOS_GetCustomer"); command.CommandTimeout = 300; database.AddInParameter(command, "@VipCode", DbType.String, vipCode); List<Customer> customers = new List<Customer>(); using (IDataReader reader = database.ExecuteReader(command)) { while (reader.Read()) { Customer customer = new Customer(); customer.CustomerId = Convert.ToInt32(reader["VIPCode_id"]); customer.CustomerCode = reader["VipCode"] as string; customer.FirstName = reader["VIPGName"] as string; customer.LastName = reader["VIPName"] as string; customer.Telephone = reader["VIPTel"] as string; if (reader["VIPBDay"] != DBNull.Value) customer.BirthDate = Convert.ToDateTime(reader["VIPBDay"]); customers.Add(customer); } } CustomerList customerList = new CustomerList(); customerList.Customers = customers; customerList.TotalCount = customers.Count; return customerList; }
public override CustomerList GetCustomer(string vipCode) { List<Customer> customers = new List<Customer>(); try { using (MySqlConnection connection = new MySqlConnection(ConnectionString)) { MySqlCommand cmd = new MySqlCommand("swSP_GetCustomer", connection); cmd.CommandType = CommandType.StoredProcedure; MySqlParameter param = new MySqlParameter("?vip_code", MySqlDbType.String); param.Direction = ParameterDirection.Input; param.Value = vipCode; cmd.Parameters.Add(param); cmd.Connection.Open(); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Customer customer = new Customer(); customer.CustomerId = Convert.ToInt32(reader["vipcode_id"]); customer.CustomerCode = reader["vipcode"] as string; customer.FirstName = reader["vipgname"] as string; customer.LastName = reader["vipname"] as string; customer.Telephone = reader["telephone"] as string; if (reader["birthday"] != DBNull.Value) customer.BirthDate = Convert.ToDateTime(reader["birthday"]); customers.Add(customer); } } } } catch (Exception) { throw; } CustomerList customerList = new CustomerList(); customerList.Customers = customers; customerList.TotalCount = customers.Count; return customerList; }