using MySql.Data.MySqlClient;//安裝MySql.Data.msi套件,再引用參考 //資料庫位址,帳號,密碼,資料庫名稱,存取編碼 MySqlConnection myConnection = new MySqlConnection("server=localhost;user id=root; password=sa123; database=mer; CharSet=utf8"); MySqlDataReader sqlDataReader; MySqlCommand sqlCmd; myConnection.Open(); DataTable data; MySqlDataAdapter da; MySqlCommandBuilder cb; data = new DataTable(); da = new MySqlDataAdapter(string.Format("SELECT * FROM ABC"), myConnection); cb = new MySqlCommandBuilder(da); da.Fill(data); //放到DataGrid顯示 dataGridView1.DataSource = data; //關閉資料庫 myConnection.Close();
沒有留言:
張貼留言