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
thanks in advance
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
}
Comment