0
0
mdmonsta developing
dataGridView1.Update();
}
In this C# code, a database connection is created and a MySql.Data.MySqlClient.MySqlCommand object is created. The MySql.Data.MySqlClient.MySqlCommand object contains the commands to be executed against the database. The MySql.Data.MySqlClient.MySqlDataAdapter object is used to Fill the DataTable object with the results of the commands. Finally, the MySql.Data.MySqlClient.MySqlConnection object is closed.
DatabaseConnection dc = new DatabaseConnection();
MySql.Data.MySqlClient.MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection("datasource = 127.0.0.1;username=root;password=;database=customer");
MySql.Data.MySqlClient.MySqlCommand command;
MySql.Data.MySqlClient.MySqlDataAdapter da;
DataTable dt;
private void button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
command = new MySql.Data.MySqlClient.MySqlCommand("Select * From customers",con);
command.ExecuteNonQuery();
dt = new DataTable();
da = new MySql.Data.MySqlClient.MySqlDataAdapter(command);
da.Fill(dt);
dataGridView1.DataSource= dt;
con.Close();
}catch(Exception ex)
{
}