Dapper basic additions and deletions change

Source: Internet
Author: User

Description

1. Do not use Dbconnection.open () in the using statement block, because the Execute method will Open and close when execution is complete.

2, in the ADO to manually open, in the using statement block when used, you can not manually close.

  PublicActionResult Select () {stringsql =@"SELECT * from Info"; List<Info> list =NULL; using(IDbConnection dbConnection =NewSqlConnection (configurationmanager.connectionstrings["default"]. ToString ())) {list= dbconnection.query<info>(SQL, CommandType.StoredProcedure).                ToList (); Sqlmapper.gridreader Gridreader=dbconnection.querymultiple (SQL);            Gridreader.read (); }            returnContent (""); }         PublicActionResult Update () {stringsql =@"Update info Set [email protected] where [email protected]"; using(IDbConnection dbConnection =NewSqlConnection (configurationmanager.connectionstrings["default"]. ToString ())) {Dbconnection.execute (SQL,NewInfo () {Name ="s Zhang", age =Ten }); }            returnContent (""); }         PublicActionResult Delete () {stringsql =@"Delete from info where [email protected]"; using(IDbConnection dbConnection =NewSqlConnection (configurationmanager.connectionstrings["default"]. ToString ())) {Dbconnection.execute (SQL,NewInfo () {age =Ten }); }            returnContent ("OK"); }         PublicActionResult Insert () {stringsql ="Insert Userinfo values (' zhao2323 ', 23, ' Shanghai ')"; stringstr =""; IDbConnection dbConnection=NULL; using(DbConnection =NewSqlConnection (configurationmanager.connectionstrings["default"]. ToString ())) {str+="before <br/>execute"+dbconnection.state;                Dbconnection.execute (SQL); STR+="after <br/>execute"+dbconnection.state; } STR+="after <br/>using"+dbconnection.state; returnContent ("OK"+str); //Execution Result://closed before execute//after execute closed//using after closed        }         PublicActionResult adonet () {stringsql ="INSERT into UserInfo values (' Zhao ', 23, ' Shanghai ')"; stringstr =""; SqlConnection Connection=NULL; using(Connection =NewSqlConnection (configurationmanager.connectionstrings["default"]. ToString ())) {using(SqlCommand command =NewSqlCommand (SQL, connection)) {connection.                    Open (); Command.                    ExecuteNonQuery (); STR+="after <br/>executenonquery:"+connection.                State; } STR+="after <br/>using command:"+connection.            State; } STR+="after <br/>using connection:"+connection.            State; returnContent ("Ok"+str); //Execution Results//after ExecuteNonQuery: Open//after using command: Open//using connection after: Closed}

Dapper basic additions and deletions change

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.