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 AdoDataSet
{
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=;");
MySqlDataAdapter adp = new MySqlDataAdapter("Select * FROM help_keyword WHERE 1 LIMIT 10",conn);
DataSet ds = new DataSet();
adp.Fill(ds, "help");
conn.Close();
DataTable dt = ds.Tables["help"];
// create panel
Panel pl = new Panel();
pl.Size = new Size(400, 400);
pl.Location = new Point(0, 0);
// Put the dt to panel
int y = 0;
foreach(DataRow dr in dt.Rows)
{
Label lb = new Label();
lb.Text = dr["name"].ToString();
lb.AutoSize = true;
lb.Location = new Point(0, y);
pl.Controls.Add(lb);
y += 20;
}
this.Controls.Add(pl);
}
}
}
Dataset .net C#
