Dapper.net Insert MSSQL Unicode garbled problem

Source: Internet
Author: User

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

Related Article

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.