c# - Dapper For MySQL Query<T>(string sql) sql has a custom variables(@rowNum) contains a special character @ -
here question.i want user page list , not want use limit.then use sql this:
select * (select @rownum:=@rownum+1 rownum,user (select @rownum:=0) r,user user.name=@name order user.name) rownum>=1 , rownum<=10
.net code this:
connection.query<t>(sql, new{name="name"}, transaction, true,commandtimeout);
and when run program,it throw exception:
message: "object reference not set instance of object.", data: { }, innerexception: null, stacktrace: " @ mysql.data.mysqlclient.mysqlconnection.get_serverthread() @ mysql.data.mysqlclient.mysqlconnection.abort() @ mysql.data.mysqlclient.mysqlcommand.executereader(commandbehavior behavior) @ dapper.sqlmapper.executereaderwithflagsfallback(idbcommand cmd, boolean wasclosed, commandbehavior behavior) @ dapper.sqlmapper.<queryimpl>d__124`1.movenext() @ system.collections.generic.list`1..ctor(ienumerable`1 collection) @ system.linq.enumerable.tolist[tsource](ienumerable`1 source) @ dapper.sqlmapper.query[t](idbconnection cnn, string sql, object param, idbtransaction transaction, boolean buffered, nullable`1 commandtimeout, nullable`1 commandtype) @ infrastructure.dapper.mysqlmapperextension.querypaged[t](idbconnection connection, object condition, string table, string orderby, int32 pageindex, int32 pagesize, string columns, boolean isor, idbtransaction transaction, nullable`1 commandtimeout) in e:\lofter\code source\netcore\mermaidloft.alchemy\mermaidloft.alchemy\src\extensions\infrastructure.dapper\mysqlmapperextension.cs:line 312 @ mermaidloft.alchemy.basedomain.userdomain.userqueryservice.findusersforpage(string username, int32 pageindex, int32 pagesize) in e:\lofter\code source\netcore\mermaidloft.alchemy\mermaidloft.alchemy\src\domains\mermaidloft.alchemy.basedomain\userdomain\userqueryservice.cs:line 30 @ mermaidloft.alchemy.quickweb.controllers.homecontroller.mysql() in e:\lofter\code source\netcore\mermaidloft.alchemy\mermaidloft.alchemy\src\mermaidloft.alchemy.quickweb\controllers\homecontroller.cs:line 40", helplink: null, source: "sapientguardian.mysql.data", hresult: -2147467261
is there idea solve problem?hope can me,thx!
if mean want check username not special character or >> easy can make loop each char in string , cast char int convert char ascii , check if
string x="aaaa"; foreach(char in x) { int s=(int)a; //(s>=65&&s<=90) capital //(s>=97&&s<=122) small if((s>=65&&s<=90) || (s>=97&&s<=122)) //do code }
Comments
Post a Comment