SQL Server 预编译执行SQLs
問題描述:
MVC5項目,利用執(zhí)行sql的方式獲取數(shù)據(jù),但是在利用預(yù)編譯執(zhí)行的時候報錯了,字段XXXwhich was not supplied.
其實就是這個參數(shù)傳了個null導(dǎo)致的。在傳參數(shù)之前做個判斷,如果為null就賦值為空串即可。
?(=String sql = "select a.Id,a.UserName,a.TrueName,ISNULL(b.OTM, '0') as Flag from SysUser a left join FIX_MatchingModel b on cast(a.Id as varchar) = b.OTM and b.Id = @matchingId Where a.DepId = @DepId order by b.OTM desc";
SqlParameter[] sqlParameters = { new SqlParameter { ParameterName = "matchingId", Value = matchingId }, new SqlParameter { ParameterName = "DepId", Value = depId } };
DbContexts DbContext = new DbContexts();
return DbContext.Database.SqlQuery<UserView>(sql, sqlParameters).ToList();
本文轉(zhuǎn)自 sshpp 51CTO博客,原文鏈接:http://blog.51cto.com/12902932/1927608,如需轉(zhuǎn)載請自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的SQL Server 预编译执行SQLs的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: toolbar.netcraft.com
- 下一篇: latch free:SQL memor