C# Populating Menu Strip from MySQL database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eihabisaac
    New Member
    • Aug 2007
    • 38

    C# Populating Menu Strip from MySQL database

    hi all

    im using C# with mysql
    i want to populate the menustrip items based on the select statement bellow
    i can select the items from the table and show them but how to popule the MenuStrip

    Code:
    private void Form2_Load(object sender, EventArgs e)
            {
                textBox1.Text = general.profile.getX().ToString();
                txtDepartment.Text = general.profile.p_department.ToString();
    
                //Load Menu
    
                MySqlConnection conn = new MySqlConnection();
                conn.ConnectionString = connString.connString.getConn();
    
                MySqlDataAdapter da = new MySqlDataAdapter();
    
                String sqlquery = "SELECT egov_d_menu_items.title FROM egov_users Inner Join egov_employees ON egov_users.ID = egov_employees.fk_user Inner Join egov_department ON egov_employees.fk_department = egov_department.ID Inner Join egov_department_menu ON egov_department_menu.fk_department = egov_department.ID Inner Join egov_d_menu_items ON egov_department_menu.fk_menu_item = egov_d_menu_items.ID where egov_department.ID = '" + txtDepartment.Text + "'";
    
                MySqlCommand myCommand = new MySqlCommand();
    
                try
                {
                    conn.Open();
                }
                catch (MySqlException myerror)
                {
                    MessageBox.Show("Error Connecting to Database: " + myerror.Message);
    
                }
    
                myCommand.Connection = conn;
                myCommand.CommandText = sqlquery;
                //start query 
                da.SelectCommand = myCommand;
                MySqlDataReader myData;
                myData = myCommand.ExecuteReader();
    
                try
                {
    
                    if (myData.HasRows)
                    {
                        while (myData.Read())
                        {
                            //code should be some were here 
    
                        }
    
                    }//if not close connection 
                    else
                    {
                        conn.Close();
                        MessageBox.Show("error", "Login Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    }
    
    
    
    
                }
                catch
                {
                    MessageBox.Show("Error Connecting to database");
                }
                //End Load Menu
                   
            }
    thanks in advance
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Code:
                MenuItem Fred = new MenuItem("Hey Wilma");
                Fred.Click +=new EventHandler(Fred_Click);

    Comment

    • eihabisaac
      New Member
      • Aug 2007
      • 38

      #3
      Hey all
      thanks tlhintoq
      i solved the problem but not with your code
      i will post the solution later so that any developer can make use of it

      Comment

      Working...