In This C# program We Will See How To Create A Menu Using Menu Strip And Add To This Menu Categories Using ToolStripMenuItem With Image And Text From MySQL Database Table From MySQL Database Using MySqlDataAdapter + DataTable + MemoryStream
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; using System.IO; namespace Csharp_menu { public partial class Menu_From : Form { public Menu_From() { InitializeComponent(); } MySqlConnection connection = new MySqlConnection("datasource=localhost;Initial Catalog='mydb';username=sk;password=tom"); private void Menu_From()(object sender, EventArgs e) { // add ToolStripMenuItem elements to menustrip using for loop MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM mypics", connection); DataTable table = new DataTable(); adapter.Fill(table); for (int i = 0; i < table.Rows.Count; i++) { /* * table => mypics * table.Rows[i][3] = image column * table.Rows[i][1] = name column * table.Rows[i][1] = id column */ byte[ ] img = (byte[])table.Rows[i][3]; MemoryStream MS = new MemoryStream(img); Image pic = Image.FromStream(MS); ToolStripMenuItem mit = new ToolStripMenuItem(table.Rows[i][1].ToString(), pic); addItems(mit, table.Rows[i][0].ToString()); menuStrip1.Items.Add(mit); } } } }