المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# - get data from MySQL DB into DataGridView



C# Programming
01-25-2010, 09:10 PM
Ok, so I have a DataGridView control with 7 columns, the column names are identical to the ones in my MySql Database and I have this code:


public partial class Form3 : Form
{
private MySqlConnection connection = new MySqlConnection();
private MySqlDataAdapter data = new MySqlDataAdapter();
public Form3()
{
InitializeComponent();
connection.ConnectionString =
"server=scionscape.org;"
+ "database=blah blah;"
+ "uid=blah blah;"
+ "password=blah;";
connection.Open();

MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from data"; //table name
data.SelectCommand = command;
DataSet dataset = new DataSet();
data.Fill(dataset, "data"); //idk??
gridInfo.DataSource = dataset; //idk?
gridInfo.DataMember = "data"; //idk?
gridInfo.Dock = DockStyle.Fill;
}

Basically what I want to do is retreive all the info from the DataBase, and show it in the DataGridView. I hope you can help me.

Regards,
Melvin

PS, lost the allignment by copy+paste, but I hope you still understand it.