public static Product GetAProduct(int productid) { using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { using (SqlCommand command = new SqlCommand("GetAProduct", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@ProductID", productid)); connection.Open(); Product temp; using (SqlDataReader reader = command.ExecuteReader()) { reader.Read(); temp = new Product( (int)reader["ProductID"], (int)reader["CategoryID"], (int)reader["ManufacturerID"], (string)reader["Name"], (int)reader["Weight"], (int)reader["Price"], (string)reader["Description"]); } return temp; } } }
ALTER PROCEDURE GetAProduct @ProductID intAS SELECT * FROM [Products] WHERE [Products].[ProductID] = @ProductIDRETURN