Code Snippets 4 U
using MySql.Data.MySqlClient;
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;

namespace AdoConnection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            MySqlConnection conn = new MySqlConnection("SERVER=localhost; DATABASE=mysql;UID=root;PASSWORD=;");
            try
            {
                conn.Open();
            }
            catch(Exception ee) {
                Console.WriteLine(ee.StackTrace);
            }

            MySqlCommand cmd = new MySqlCommand("SELECT * FROM help_category WHERE 1 LIMIT 10 ", conn);
            MySqlDataReader mdr = cmd.ExecuteReader();
            // create panel and add to form
            Panel pl = new Panel();
            pl.Size = new Size(400, 400);
            pl.Location = new Point(0, 0);
            
            int y = 0;
            while (mdr.Read())
            {
                String ext = mdr["name"].ToString();
                TextBox b = new TextBox();
                b.AutoSize = true;
                b.ReadOnly = true;
                b.BorderStyle = 0;
                b.TabStop = false;
                b.Location = new Point(0, y);
                b.Text = ext;
                y += 20;
                // add button to panel
                pl.Controls.Add(b);
            }


            this.Controls.Add(pl);
            mdr.Close();
            conn.Close();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

+ two = seven