Make the Products property to return List of Products
i.e
public virtual List<products> Products</products>
Change
public List<products> getProducts(Category category)</products>
as static method and only allow to pass categoryID as parameter.
i.e.
public static List<products> GetProducts(int categoryID)</products>
and just do the in Category class as
public virtual List<products> Products
{
get
{
return ProductDB.GetProducts(categoryID);
}
}
For binding the datagrid you have to create a new method in ProductDB class
i.e.
public static List<products> GetProductsByCategoryName(string categoryName)
and your select query will be
select Product.* from Product INNER JOIN Category ON Category.CategoryID = Product.CategoryID WHERE
CategoryName like @CategoryName
and code will be
mycommand.Parameters.AddWithValue("@Categoryname", categoryName);
I hope this will help you.