mysql.data.dll下載_c#連接mysql必要插件 全部版本下載:http://hovertree.com/h/bjaf/0sft36s9.htm mysql.data.dll是C#操作MYSQL的驅動文件,是c#連接mysql必要插件,使c#語言更簡潔的操作mysql資料庫。當你的電腦彈 ...
mysql.data.dll下載_c#連接mysql必要插件
全部版本下載:http://hovertree.com/h/bjaf/0sft36s9.htm
mysql.data.dll是C#操作MYSQL的驅動文件,是c#連接mysql必要插件,使c#語言更簡潔的操作mysql資料庫。當你的電腦彈出提示“丟失mysql.data.dll”或“無法找到mysql.data.dll”等錯誤問題,請下載本站為你提供的dll文件,使用它可以幫助用戶解決上述問題。
dll文件修複方法:
1、解壓下載的文件。
2、複製文件“mysql.data.dll”到系統目錄下。
3、系統目錄一般為:C:\WINNT\System32 64位系統為C:\Windows\SysWOW64
4、最後點擊開始菜單-->運行-->輸入regsvr32 mysql.data.dll 後,回車即可解決錯誤提示!
第三方組件:Mysql.Data.dll
說明:下載Mysql.Data.dll,然後在項目中添加該組件的引用,在代碼頁里輸入using Mysql.Data.MysqlClient,我們就可以順利的使用該類庫的函數建立連接了。
以下是幾個常用函數:
1 #region 建立MySql資料庫連接 2 /// <summary> 3 /// 建立資料庫連接. 4 /// </summary> 5 /// <returns>返回MySqlConnection對象</returns> 6 public MySqlConnection getmysqlcon() 7 { 8 //http://sosoft.cnblogs.com/ 9 string M_str_sqlcon = "server=localhost;user id=root;password=root;database=abc"; //根據自己的設置 10 MySqlConnection myCon = new MySqlConnection(M_str_sqlcon); 11 return myCon; 12 } 13 #endregion 14 15 #region 執行MySqlCommand命令 16 /// <summary> 17 /// 執行MySqlCommand 18 /// </summary> 19 /// <param name="M_str_sqlstr">SQL語句</param> 20 public void getmysqlcom(string M_str_sqlstr) 21 { 22 MySqlConnection mysqlcon = this.getmysqlcon(); 23 mysqlcon.Open(); 24 MySqlCommand mysqlcom = new MySqlCommand(M_str_sqlstr, mysqlcon); 25 mysqlcom.ExecuteNonQuery(); 26 mysqlcom.Dispose(); 27 mysqlcon.Close(); 28 mysqlcon.Dispose(); 29 } 30 #endregion 31 32 #region 創建MySqlDataReader對象 33 /// <summary> 34 /// 創建一個MySqlDataReader對象 35 /// </summary> 36 /// <param name="M_str_sqlstr">SQL語句</param> 37 /// <returns>返回MySqlDataReader對象</returns> 38 public MySqlDataReader getmysqlread(string M_str_sqlstr) 39 { 40 MySqlConnection mysqlcon = this.getmysqlcon(); 41 MySqlCommand mysqlcom = new MySqlCommand(M_str_sqlstr, mysqlcon); 42 mysqlcon.Open(); 43 MySqlDataReader mysqlread = mysqlcom.ExecuteReader(CommandBehavior.CloseConnection); 44 return mysqlread; 45 } 46 #endregion
1 using System.Data; 2 3 using MySql.Data.MySqlClient; 4 5 6 7 8 9 private MySqlConnection conn; 10 11 private DataTable data; 12 13 private MySqlDataAdapter da; 14 15 private MySqlCommandBuilder cb; 16 17 private DataGrid dataGrid; 18 19 20 21 private void connectBtn_Click(object sender, System.EventArgs e) 22 23 { 24 25 if (conn != null) 26 27 conn.Close(); 28 29 30 31 string connStr = String.Format("server={0};user id={1}; password={2}; port={3}; database=mysql; pooling=false; charset=utf8", 32 33 server.Text, userid.Text, password.Text, 3306); 34 35 36 37 try 38 39 { 40 41 conn = new MySqlConnection( connStr ); 42 43 conn.Open(); 44 45 46 47 GetDatabases(); 48 49 MessageBox.Show("連接資料庫成功!"); 50 51 } 52 53 catch (MySqlException ex) 54 55 { 56 57 MessageBox.Show( "Error connecting to the server: " + ex.Message ); 58 59 } 60 61 } 62 63 64 65 private void GetDatabases() 66 67 { 68 69 MySqlDataReader reader = null; 70 71 MySqlCommand cmd = new MySqlCommand("SHOW DATABASES", conn); 72 73 74 75 try 76 77 { 78 79 reader = cmd.ExecuteReader(); 80 81 databaseList.Items.Clear(); 82 83 while (reader.Read()) 84 85 { 86 87 databaseList.Items.Add( reader.GetString(0) ); 88 89 } 90 91 } 92 93 catch (MySqlException ex) 94 95 { 96 97 MessageBox.Show("Failed to populate database list: " + ex.Message ); 98 99 } 100 101 finally 102 103 { 104 105 if (reader != null) reader.Close(); 106 107 } 108 109 } 110 111 112 113 private void databaseList_SelectedIndexChanged(object sender, System.EventArgs e) 114 115 { 116 117 MySqlDataReader reader = null; 118 119 conn.ChangeDatabase(databaseList.SelectedItem.ToString()); 120 121 //http://sosoft.cnblogs.com/ 122 123 MySqlCommand cmd = new MySqlCommand("SHOW TABLES", conn); 124 125 try 126 127 { 128 129 reader = cmd.ExecuteReader(); 130 131 tables.Items.Clear(); 132 133 while (reader.Read()) 134 135 { 136 137 tables.Items.Add( reader.GetString(0) ); 138 139 } 140 141 } 142 143 catch (MySqlException ex) 144 145 { 146 147 MessageBox.Show("Failed to populate table list: " + ex.Message ); 148 149 } 150 151 finally 152 153 { 154 155 if (reader != null) reader.Close(); 156 157 } 158 159 } 160 161 162 163 private void tables_SelectedIndexChanged(object sender, System.EventArgs e) 164 165 { 166 167 data = new DataTable(); 168 169 170 171 da = new MySqlDataAdapter("SELECT * FROM " + tables.SelectedItem.ToString(), conn ); 172 173 cb = new MySqlCommandBuilder( da ); // 此處必須有,否則無法更新 174 175 176 177 da.Fill( data ); 178 179 180 181 dataGrid.DataSource = data; 182 183 } 184 185 186 187 private void updateBtn_Click(object sender, System.EventArgs e) 188 189 { 190 191 DataTable changes = data.GetChanges(); 192 193 da.Update( changes ); 194 195 data.AcceptChanges(); 196 197 }
http://www.cnblogs.com/sosoft/p/kaifajishu.html