• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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)parentItem["cat_name"]);
    Menu1.FindItem("Products").ChildItems.Add(categoryItem);

    foreach (DataRow childItem in parentItem.GetChildRows("Children"))
    {
        MenuItem childrenItem = new MenuItem((string)childItem["prod_name"]);
      categoryItem.ChildItems.Add(childrenItem);
    }
  }
}

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["cat_id"],
     ds.Tables["start_menu_setup"].Columns["cat_id"]);
  return ds;
}


thanks in advance Andrew
0
REA_ANDREW
Asked:
REA_ANDREW
  • 2
1 Solution
 
vinodhsomasekharanCommented:
Hai,

Try this..

foreach (DataRow childItem in parentItem.GetChildRows("Children"))
    {
      int count = (int)childItem["prod_count"];
      if(count>0)
     {
       MenuItem childrenItem = new MenuItem((string)childItem["prod_name"]);
       categoryItem.ChildItems.Add(childrenItem);
     }
    }

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
0
 
vinodhsomasekharanCommented:

Hai..
Sorry i have put the wrong condition...

in the parent table itself u have the prod_counter value ..

so before going to the inner loop .. u can check u r condition there..

foreach (DataRow parentItem in ds.Tables["menu_creator"].Rows)
  {
    MenuItem categoryItem = new MenuItem((string)parentItem["cat_name"]);
    Menu1.FindItem("Products").ChildItems.Add(categoryItem);

   int count = (int)parentItem["prod_counter"];
   // just get the value of the prod counter if its greater than 1 then go to add the child items.. else skip it..
     if(count>1)
     {
         foreach (DataRow childItem in parentItem.GetChildRows("Children"))
        {
           MenuItem childrenItem = new MenuItem((string)childItem["prod_name"]);
           categoryItem.ChildItems.Add(childrenItem);
        }
     }
  }


hope it helps u

Regards
Vinu
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now