示例#1
0
        public static bool SaveCustomer(Customer customer)
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);
                using (connection)
                {
                    SqlCommand command = connection.CreateCommand();
                    using (command)
                    {
                        command.CommandText = "INSERT INTO customer (firstname, lastname, address, zip, city) VALUES (@firstname, @lastname, @address, @zip, @city)";
                        command.Parameters.AddWithValue("@firstname", customer.Firstname);
                        command.Parameters.AddWithValue("@lastname", customer.Lastname);
                        command.Parameters.AddWithValue("@address", customer.Address);
                        command.Parameters.AddWithValue("@zip", customer.Zip);
                        command.Parameters.AddWithValue("@city", customer.City);

                        connection.Open();
                        command.ExecuteNonQuery();
                        return true;
                    }
                }
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                return false;
            }
        }
示例#2
0
 public bool SaveCustomer(string firstname, string lastname, string address, string zip, string city)
 {
     Customer newCustomer = new Customer(firstname, lastname, address, zip, city);
     if(DataReader.SaveCustomer(newCustomer))
     {
         Load();
         return true;
     }
     else return false;
 }