Asp.net+mysql the operation of the site data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.