Csharp:dapper Sample
Last Update:2015-07-26
Source: Internet
Author: User
<span id="Label3"></p><p><p>You can find Dapper on Google Code here:http://code.google.com/p/dapper-dot-net/and the GitHub distro here:https://gith Ub.com/samsaffron/dapper-dot-net.</p></p><pre class="brush:csharp;gutter:true;"> <summary>///additional Records///</summary>///<param name= "bookplacelistinfo" >< /param>///<returns></returns> public int insertbookplacelist (bookplacelistinfo bookPlaceList ) {int ret = 0; Try {list<bookplacelistinfo> list=new list<bookplacelistinfo> (); List. ADD (bookplacelist); StringBuilder str = new StringBuilder (); Str. Append ("INSERT into bookplacelist"); Str. Append ("([bookplacename], [bookplacecode], [bookplaceparent]) VALUES"); Str. Append ("(@BookPlaceName, @BookPlaceCode, @BookPlaceParent)"); Ret=sqlmapperutil.insertmultiple<bookplacelistinfo> (str. ToString (), list, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return ret; }//<summary> Append multiple Records//</summary>//<param name= "bookplacelist" ></param>//<r eturns></returns> public int Insertbookplacelistmore (list<bookplacelistinfo> BookPlaceList) { int ret = 0; Try {StringBuilder str = new StringBuilder (); Str. Append ("INSERT into bookplacelist"); Str. Append ("([bookplacename], [bookplacecode], bookplaceparent]) VALUES"); Str. Append ("(@BookPlaceName, @BookPlaceCode, @BookPlaceParent)"); ret = sqlmapperutil.insertmultiple<bookplacelistinfo> (str. ToString (), bookplacelist, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return ret; }///<summary>//modify Record///</summary>///<param name= "bookplacelistinfo" >< /param>///<returns></returns> public int updatebookplacelist (bookplacelistinfo Bookplacelist) {int ret = 0; Try {list<bookplacelistinfo> List = new List<bookplacelistinfo> (); List. ADD (bookplacelist); StringBuilder str = new StringBuilder (); Str. Append ("UPDATE bookplacelist SET"); Str. Append ("[bookplacename][email protected],"); Str. Append ("[bookplacecode][email protected],"); Str. Append ("[bookplaceparent][email protected]"); Str. Append ("where"); Str. Append ("[bookplaceid][email protected]"); ret = sqlmapperutil.insertmultiple<bookplacelistinfo> (str. ToString (), list, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return ret; }///<summary>/Delete Records///</summary>///<param name= "bookplaceidinfo" ></param>///<returns>& lt;/returns> public bool Deletebookplacelist (int bookplaceid) {bool ret = false; Try {int temp = 0; StringBuilder str = new StringBuilder (); Str. Append ("deletebookplacelist WHERE Bookplaceid = @BookPlaceID"); temp = Sqlmapperutil.insertupdateordeletesql (str. ToString (), New {bookplaceid = bookplaceid}, sqlhelper.connectionstring); If (temp! = 0) {ret = true; }} catch (SqlException Ex) {throw ex; } return ret; }///<summary>///query Record///</summary>///<param name= "bookplaceidinfo" ></ Param>///<returns></returns> Public BookPlacelistinfo selectbookplacelist (int bookplaceid) {bookplacelistinfo bookplacelist = null; Try {StringBuilder str = new StringBuilder (); Str. Append ("select * from bookplacelist WHERE Bookplaceid = @BookPlaceID"); Bookplacelist = sqlmapperutil.sqlwithparamssingle<bookplacelistinfo> (str. ToString (), New {bookplaceid = bookplaceid}, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return bookplacelist; }///<summary>///query All records///</summary>///<returns></returns> Public list<bookplacelistinfo> selectbookplacelistall () {list<bookplacelistinfo> List = new List<bookplacelistinfo> (); Try {string str = "select * from bookplacelist"; List = Sqlmapperutil.sqlwithparams<bookplacelistinfo> (str, null, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return list; }</pre><p><p>Nearly half as much as sqlhelper than bulk data insertion</p></p><p><p>Csharp:dapper Sample</p></p></span>