Example #1
0
 public void Delete(ADOSupplier sup)
 {
     if (sup != null)
     {
         using (SqlCommand com = new SqlCommand(
                    "DELETE Suppliers WHERE SupplierId = @SupId",
                    db.Connection))
         {
             com.Parameters.AddWithValue("SupId", sup.SupplierId);
             com.ExecuteNonQuery();
         }
     }
 }
Example #2
0
 public void Create(ADOSupplier sup)
 {
     if (sup != null)
     {
         using (SqlCommand com = new SqlCommand(
                    "INSERT INTO Suppliers (Name) VALUES (@SName)",
                    db.Connection))
         {
             com.Parameters.AddWithValue("SName", sup.Name);
             com.ExecuteNonQuery();
         }
     }
 }
Example #3
0
 public void Update(ADOSupplier sup)
 {
     if (sup != null)
     {
         using (SqlCommand com = new SqlCommand(
                    "UPDATE Suppliers SET Name = @SName WHERE SupplierId = @SupId",
                    db.Connection))
         {
             com.Parameters.AddWithValue("SName", sup.Name);
             com.Parameters.AddWithValue("SupId", sup.SupplierId);
             com.ExecuteNonQuery();
         }
     }
 }
Example #4
0
        public ADOSupplier GetById(int id)
        {
            ADOSupplier sup = null;

            using (SqlCommand com = new SqlCommand(
                       "SELECT * FROM Suppliers WHERE SupplierId = @SId",
                       db.Connection))
            {
                com.Parameters.AddWithValue("SId", id);
                using (SqlDataReader reader = com.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        sup = new ADOSupplier()
                        {
                            SupplierId = (int)reader[0],
                            Name       = (string)reader[1]
                        }
                    }
                    ;
                }
            }
            return(sup);
        }