REA_ANDREW
asked on
Data Adapter get Value
I have a function which creates two datasets, from this I then return the data into a function called populate menu.
In the sql I have a value called prod_counter. If this is equal to one I donot want to perform a task. If it is greater I do.
The function creates a menu with sub menus, so looking at my script if the value prod_counter in the SQL is one then I do not want to create submenus.
Here is my code.
private void PopulateMenu()
{
DataSet ds = GetDataSetForMenu();
foreach (DataRow parentItem in ds.Tables["menu_creator"]. Rows)
{
MenuItem categoryItem = new MenuItem((string)parentIte m["cat_nam e"]);
Menu1.FindItem("Products") .ChildItem s.Add(cate goryItem);
foreach (DataRow childItem in parentItem.GetChildRows("C hildren"))
{
MenuItem childrenItem = new MenuItem((string)childItem ["prod_nam e"]);
categoryItem.ChildItems.Ad d(children Item);
}
}
}
private DataSet GetDataSetForMenu()
{
SqlDataAdapter adCat = new SqlDataAdapter("SELECT cat_id, cat_name, link_field, prod_counter FROM menu_creator ORDER BY cat_menu_order", Connection);
SqlDataAdapter adProd = new SqlDataAdapter("SELECT cat_id, prod_count, prod_name, cat_name FROM start_menu_setup ORDER BY prod_name", Connection);
DataSet ds = new DataSet();
adCat.Fill(ds, "menu_creator");
adProd.Fill(ds, "start_menu_setup");
ds.Relations.Add("Children ",
ds.Tables["menu_creator"]. Columns["c at_id"],
ds.Tables["start_menu_setu p"].Column s["cat_id" ]);
return ds;
}
thanks in advance Andrew
In the sql I have a value called prod_counter. If this is equal to one I donot want to perform a task. If it is greater I do.
The function creates a menu with sub menus, so looking at my script if the value prod_counter in the SQL is one then I do not want to create submenus.
Here is my code.
private void PopulateMenu()
{
DataSet ds = GetDataSetForMenu();
foreach (DataRow parentItem in ds.Tables["menu_creator"].
{
MenuItem categoryItem = new MenuItem((string)parentIte
Menu1.FindItem("Products")
foreach (DataRow childItem in parentItem.GetChildRows("C
{
MenuItem childrenItem = new MenuItem((string)childItem
categoryItem.ChildItems.Ad
}
}
}
private DataSet GetDataSetForMenu()
{
SqlDataAdapter adCat = new SqlDataAdapter("SELECT cat_id, cat_name, link_field, prod_counter FROM menu_creator ORDER BY cat_menu_order", Connection);
SqlDataAdapter adProd = new SqlDataAdapter("SELECT cat_id, prod_count, prod_name, cat_name FROM start_menu_setup ORDER BY prod_name", Connection);
DataSet ds = new DataSet();
adCat.Fill(ds, "menu_creator");
adProd.Fill(ds, "start_menu_setup");
ds.Relations.Add("Children
ds.Tables["menu_creator"].
ds.Tables["start_menu_setu
return ds;
}
thanks in advance Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this..
foreach (DataRow childItem in parentItem.GetChildRows("C
{
int count = (int)childItem["prod_count
if(count>0)
{
MenuItem childrenItem = new MenuItem((string)childItem
categoryItem.ChildItems.Ad
}
}
just get the prod_count from the childrow and check if the count > 0 then add the item to the menu else skip it
will this solve u r prob...
regards
Vinu