1 usingSystem;2 usingSystem.Data;3 usingSystem.Text;4 usingSystem.Configuration;5 usingsystem.web;6 usingSystem.Web.Security;7 usingSystem.Web.UI;8 usingSystem.Web.UI.HtmlControls;9 usingSystem.Web.UI.WebControls;Ten usingSystem.Web.UI.WebControls.WebParts; One usingMySql.Data.MySqlClient;//☆ A - namespacedb_ - { the Public classDB - { - - PublicDB () + { - //Add constructor logic here + } A at Publicmysqlconnection conntent () - { - stringConstr ="Data source=127.0.0.1;port=3306;database=test; User Id=root; Password=root; Charset=utf8;allow Zero Datetime=true"; -Mysqlconnection con =Newmysqlconnection (constr); - Try - { in con. Open (); - returnCon//Success to } + Catch(Exception ex) - { the return NULL;//Connection Open Exception occurred * } $}//connection string, returning mysqlconnection linked objectPanax Notoginseng - PublicDataSet Select (stringSQLSTR)//returns a dataset dataset or null the { +Mysqldataadapter Myadapter =NewMysqldataadapter (Sqlstr, Conntent ()); ADataSetSelect=NewDataSet (); the intSuc_count = Myadapter. Fill (Select); + if(Select!=NULL) {return Select; } - Else{return NULL; } $ } $ - PublicMysqldatareader Select1 (stringSQLSTR)//returns a Mysqldatareader object, or null - { theMysqlcommand myCMD =NewMysqlcommand (Sqlstr,conntent ()); - TryWuyi { theMysqldatareader Select1 =myCMD. ExecuteReader (); - if(Select1! =NULL){returnSelect1;} Wu Else{return NULL; } - } About Catch(Exception ex) $ { - return NULL; - } - } A + Public BOOLZSG (stringSQLSTR)//perform actions based on the SQLSTR and connection objects of the descendant the{//Call the ZSG () function to delete and modify the operation, success true, failure false -Mysqlcommand myCMD =NewMysqlcommand (Sqlstr, Conntent ()); $ Try the { the if(myCMD. ExecuteNonQuery () >0) the{return true;//Success} the Else -{return false; } in } the Catch{return false; } the } About } the}
Asp.net+mysql the operation of the site data