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

مشاهدة النسخة كاملة : Getting info from database in gridview



C# Programming
01-30-2010, 01:00 AM
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=uhhhhh;"
+ "database=uhhhh;"
+ "uid=uhhhh;"
+ "password=uhhh;";
connection.Open();

MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from data";

data.SelectCommand = command;
DataSet dataset = new DataSet();
data.Fill(dataset, "data");

gridInfo.DataSource = dataset;
gridInfo.DataMember = "data";
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