1. Effect:
2, processing method:
/// <summary> ///Insert Single SQL/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "SQL" ></param> /// <param name= "param" ></param> /// <param name= "connectionString" ></param> /// <returns></returns> Public Static intInsert<t> (stringSqlDynamicparam =NULL,stringConnectionString =NULL)whereT:class,New() { using(IDbConnection conn =OpenConnection (connectionString)) { returnConn. Execute (SQL, (Object) param,NULL,NULL,NULL); } }
Public Static ReadOnly string @" Insert into Spreadapierrormsgs (id,controllername,actionname,message,soluway,createdate) values (@Id, @ Controllername, @ActionName, @Message, @SoluWay, @CreateDate)";
/// <summary> ///Insert Single SQL/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "SQL" ></param> /// <param name= "param" ></param> /// <param name= "connectionString" ></param> /// <returns></returns> Public Static intInsert<t> (stringSqlDynamicparam =NULL,stringConnectionString =NULL)whereT:class,New() { using(IDbConnection conn =OpenConnection (connectionString)) { returnConn. Execute (SQL, (Object) param,NULL,NULL,NULL); } }
Ps:dapper Source:
/// <summary> ///This class represents a SQL string, it can be used if you need to denote your parameter are a Char vs VarChar vs Nvarc Har vs NChar/// </summary> Sealed Partial classDbString:Reasonable.Spread.Dapper.SqlMapper.ICustomQueryParameter {/// <summary> ///Create a new dbstring/// </summary> PublicDbstring () {Length =-1; } /// <summary> ///Ansi vs Unicode/// </summary> Public BOOLIsansi {Get;Set; } /// <summary> ///Fixed Length/// </summary> Public BOOLIsfixedlength {Get;Set; } /// <summary> ///Length of the string-1 for Max/// </summary> Public intLength {Get;Set; } /// <summary> ///The value of the string/// </summary> Public stringValue {Get;Set; } /// <summary> ///ADD the parameter to the command ... internal use only/// </summary> /// <param name= "command" ></param> /// <param name= "name" ></param> Public voidAddparameter (IDbCommand command,stringname) { if(isfixedlength && Length = =-1) { Throw NewInvalidOperationException ("If specifying Isfixedlength, a Length must also be specified"); } varparam =command. CreateParameter (); Param. ParameterName=name; Param. Value= (Object) Value??DBNull.Value; if(Length = =-1&& Value! =NULL&& Value.length <=4000) {param. Size=4000; } Else{param. Size=Length; } param. DbType= Isansi? (isfixedlength?) DbType.AnsiStringFixedLength:DbType.AnsiString): (isfixedlength?DbType.StringFixedLength:DbType.String); Command. Parameters.Add (param); } }
Dapper.net Insert MSSQL Unicode garbled problem