码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server 预编译执行SQLs

时间:2017-05-19 22:10:16      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:zz

问题描述:

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();

技术分享


SQL Server 预编译执行SQLs

标签:zz

原文地址:http://12902932.blog.51cto.com/12892932/1927608

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!