con datasource localhost database museum username root password passwo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
con = "datasource=localhost;" + "database=museum;" + "username=root;" + "password=password";
string comand = "select * from tablename";
DataTable dt = new DataTable();
using (MySqlConnection con = new MySqlConnection())
{
con.ConnectionString = connection;
MySqlCommand com = new MySqlCommand(comand, con);
try
{
con.Open();
using (MySqlDataReader dr = com.ExecuteReader())
{
if (dr.HasRows)
{
dt.Load(dr);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
con.Close();
}
dataGridView1.DataSource = dt;