C # Simple, basic way to operate MySQL:
1 classMysqlmanager2 {3 Mysqlconnection Conn; 4 5 PublicMysqlmanager (stringstrconn)6 {7conn =Newmysqlconnection (strconn);8 } 9 Ten PublicDataTable GetData (stringstrcmd) One { A Try - { -Mysqldataadapter ADPT =NewMysqldataadapter (STRCMD, conn); theDataTable dt =NewDataTable (); - ADPT. Fill (DT); - returnDT; - } + Catch(Exception ex) - { +MessageBox.Show (ex. Message,"Error-getdata", MessageBoxButtons.OK, messageboxicon.error); A return NULL; at } - finally - { - if(Conn. state = =ConnectionState.Open) Conn. Close (); - } - } in - Public voidOperate (stringstrcmd) to { + Try - { the Conn. Open (); *Mysqlcommand cmd =NewMysqlcommand (STRCMD, conn); $ cmd. ExecuteNonQuery ();Panax Notoginseng Conn. Close (); - } the Catch(Exception ex) + { AMessageBox.Show (ex. Message,"error-operate", MessageBoxButtons.OK, messageboxicon.error); the } + finally - { $ if(Conn. state = =ConnectionState.Open) Conn. Close (); $ } - } -}
C # operation MySQL