473,769 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Populating Menu Strip from MySQL database

38 New Member
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

Expand|Select|Wrap|Line Numbers
  1. private void Form2_Load(object sender, EventArgs e)
  2.         {
  3.             textBox1.Text = general.profile.getX().ToString();
  4.             txtDepartment.Text = general.profile.p_department.ToString();
  5.  
  6.             //Load Menu
  7.  
  8.             MySqlConnection conn = new MySqlConnection();
  9.             conn.ConnectionString = connString.connString.getConn();
  10.  
  11.             MySqlDataAdapter da = new MySqlDataAdapter();
  12.  
  13.             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 + "'";
  14.  
  15.             MySqlCommand myCommand = new MySqlCommand();
  16.  
  17.             try
  18.             {
  19.                 conn.Open();
  20.             }
  21.             catch (MySqlException myerror)
  22.             {
  23.                 MessageBox.Show("Error Connecting to Database: " + myerror.Message);
  24.  
  25.             }
  26.  
  27.             myCommand.Connection = conn;
  28.             myCommand.CommandText = sqlquery;
  29.             //start query 
  30.             da.SelectCommand = myCommand;
  31.             MySqlDataReader myData;
  32.             myData = myCommand.ExecuteReader();
  33.  
  34.             try
  35.             {
  36.  
  37.                 if (myData.HasRows)
  38.                 {
  39.                     while (myData.Read())
  40.                     {
  41.                         //code should be some were here 
  42.  
  43.                     }
  44.  
  45.                 }//if not close connection 
  46.                 else
  47.                 {
  48.                     conn.Close();
  49.                     MessageBox.Show("error", "Login Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
  50.                 }
  51.  
  52.  
  53.  
  54.  
  55.             }
  56.             catch
  57.             {
  58.                 MessageBox.Show("Error Connecting to database");
  59.             }
  60.             //End Load Menu
  61.  
  62.         }
  63.  
thanks in advance
Mar 16 '09 #1
2 4555
tlhintoq
3,525 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1.             MenuItem Fred = new MenuItem("Hey Wilma");
  2.             Fred.Click +=new EventHandler(Fred_Click);
  3.  
Mar 16 '09 #2
eihabisaac
38 New Member
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
Mar 16 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3902
by: Jason | last post by:
I have a client that would like to have drop down menus added to a nav bar that is generated from MySQL. Is it possible to have a dynamically driven DHTML menu from MySQL? example link http://www.msnbc.msn.com/Default.aspx?p1=0
0
2083
by: Brian Henry | last post by:
I thought this was useful, its a extender i just wrote for the new .NET menu strip and status strip to extend the menu items to add a status message so when a mouse rolls over the item it displays the text on the status strip lable specified for the extender.. all you have to do is copy this to a code file, and add it as a control to your form. set the status lable property of the extender control then set the status mesages of the menu...
6
6878
by: TyBreaker | last post by:
What is the best way to create a menu bar like the Office menu bar ie one that can dock to the four corners of the screen? Is it a standard windows form or is it some other more specialised control? -- ______ ___ __ /_ __/_ __/ _ )_______ ___ _/ /_____ ____ / / / // / _ / __/ -_) _ `/ '_/ -_) __/ /_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/ /___/
0
1831
by: steffen_home_92 | last post by:
hi ng, I actually want to program an application whose main window contains a menu strip and a tree view control. In the main menu there are items I want to use for a context menu strip in the tree view but if I add a menu item from the main menu strip to a context menu it disappears from the main menu. Additionaly there's no (!) Clone-methode in the ToolStripMenuItem class, so I can't just copy the menu item at runtime. Can anybody...
8
2109
by: gs | last post by:
I was able to set tooltips on objects other than main menu. I would like to get the effect of tooltip or microhelp in the bottom status bar when the mouse is hovering over a submenu item. How do I do that? For example in outlook express, when one expand a main menu item and holds mouse over one of the enable sub menu item, one would see some sort microhelp text in the status bar in the bottom
16
2888
by: Head In A Pan | last post by:
OK... I am now heading into day 3 of attempting to populate a database through my flash form!! I figure I need some help before I crack! I just can't get it to work at all... I am able to get my variables from flash for the purposes of sending them via email but need a PHP/SQL guru to tell me what I am doing so horribly wrong in this case... it may be something really obvious to someone above my novice level - Please? ;) Here's my code:...
2
5255
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu, but I am unable to store a variable for it. Here is a rough copy of what I am making: <html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
7
2003
by: sosamv | last post by:
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres a <textarea> where the admin enters the tree array, example: , ], , , ] I want to create a "preview" button that would open a popup with the preview of the tree.... the script of the pop-up to create the tree preview is:
14
4339
by: Philth | last post by:
Hi there, I've essentially got a form with several drop down, each populated by columns in various tables. The populating bit works fine - the column rows appear as they should in the menu. Ideally the user needs to make their selections, and enter the form into a new database table. The problem is, when the selection is entered into the new table, only the first word of the string is entered. For example, the drop down may have...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.