public void Insert(Product product) { const string query = "INSERT INTO Products (ProductName,ProductDescription,Quantity,IsOnSale) VALUES(@ProductName,@ProductDescription,@Quantity,@IsOnSale)"; using (var conn = new SqlConnection(connString)) { conn.Query(query, product); } }
public void Insert(Product product) { string query = string.Format("INSERT INTO Products (ProductName,ProductDescription,Quantity,IsOnSale) VALUES('{0}','{1}','{2}','{3}')", product.ProductName, product.ProductDescription, product.Quantity, product.IsOnSale); using (var connection = new SqlConnection(connString)) { using (var command = new SqlCommand(query, connection)) { connection.Open(); command.ExecuteNonQuery(); } } }
public void Insert(Product product) { _productsDb.Products.Add(product); }