public Category GetCategoryAdo(int categoryId) { SqlConnection conn = pga.OpenConnection(); SqlCommand command = new SqlCommand("spGetCatgory", conn); command.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter categoryIdParam = pga.CreateParameterByValueAndName(categoryId, "@categoryId"); command.Parameters.Add(categoryIdParam); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Category category = new Category(); category.CategoryId = Convert.ToInt32(reader["CategoryId"]); category.CategoryName = (reader["CategoryName"]).ToString(); return(category); } } pga.CloseConnection(conn); return(null); //Create Procedure spGetCategory @categoryId int //as //Begin //Select* from Category //where CategoryId = @categoryId //end }
public Product GetProductByNameAdo(string ProductName) { // Create Procedure GetProductByName //@ProductName varchar(100) //as //begin //select* from Product //where ProductName like '%' + @ProductName + '%' //end SqlConnection conn = pga.OpenConnection(); SqlCommand command = new SqlCommand("GetProductByName", conn); command.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter productNameParam = pga.CreateParameterByValueAndName(ProductName, "@ProductName"); command.Parameters.Add(productNameParam); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Product product = new Product(); product.ProductId = Convert.ToInt32(reader["ProductId"]); product.ProductName = (reader["ProductName"]).ToString(); product.CategoryId = Convert.ToInt32(reader["CategoryId"]); product.ManufacturerId = Convert.ToInt32(reader["ManufacturerId"]); product.Description = (reader["Description"].ToString()); product.Stock = Convert.ToInt32(reader["Stock"]); product.Price = Convert.ToInt32(reader["Price"]); product.Display = (reader["Display"].ToString()); product.Processor = (reader["Processor"].ToString()); product.Memory = (reader["Memory"].ToString()); product.VideoMemory = (reader["VideoMemory"].ToString()); product.HDD = (reader["HDD"].ToString()); product.Camera = (reader["Camera"].ToString()); product.Photo = (reader["Photo"].ToString()); return(product); } } pga.CloseConnection(conn); return(null); }