SQL Server 预编译执行SQLs
問題描述:
MVC5項目,利用執行sql的方式獲取數據,但是在利用預編譯執行的時候報錯了,字段XXXwhich was not supplied.
其實就是這個參數傳了個null導致的。在傳參數之前做個判斷,如果為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();
本文轉自 sshpp 51CTO博客,原文鏈接:http://blog.51cto.com/12902932/1927608,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的SQL Server 预编译执行SQLs的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: toolbar.netcraft.com
- 下一篇: latch free:SQL memor