String stringconnStr = String.Format("server={0};user id={1}; password={2}; database=test; pooling=false","localhost", "root", "123456"); MySqlConnection conn = new MySqlConnection(stringconnStr); conn.Open(); String sql = "select * from stutbl"; //MySqlCommand command = new MySqlCommand(sql, conn); //建立 Command 對象 //MySqlDataReader reder = command.ExecuteReader(); //while (reder.Read()) //{ // //讀出內容列 // string str = reder["user_name"].ToString(); // //讀取分類列 // string str1 = reder["user_pass"].ToString(); // //分別爲文本框加載數據 //} MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); DataSet ds = new DataSet();//建立DataSet實例 da.Fill(ds, "testtabel");//使用DataAdapter的Fill方法(填充),調用SELECT命令 DataTable tabel = ds.Tables["testtabel"]; foreach (DataRow drCurrent in tabel.Rows) { String aa = drCurrent["user_name"].ToString(); } conn.Close();//關閉數據庫
using MySql.Data.MySqlClient;sql