我的VS2013中,用Ado.net给SQLParameter赋值的时候,当赋值null的时候,生成的sql语句是default
/// <summary>
/// 增加一条数据
/// </summary>
public bool Add(Model.WechatDocuments model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into WechatDocuments(");
strSql.Append("DocumentName,DocumentPath,DocumentFormatType,UploadBy,UploadDate,UploaderOpenId,BillNo,BillAmount,Reviewedby,ReviewedDate,ReviewedResult,ReviewedComment)");
strSql.Append(" values (");
strSql.Append("@DocumentName,@DocumentPath,@DocumentFormatType,@UploadBy,@UploadDate,@UploaderOpenId,@BillNo,@BillAmount,@Reviewedby,@ReviewedDate,@ReviewedResult,@ReviewedComment)");
SqlParameter[] parameters = {
new SqlParameter("@DocumentName", SqlDbType.VarChar,),
new SqlParameter("@DocumentPath", SqlDbType.VarChar,),
new SqlParameter("@DocumentFormatType", SqlDbType.VarChar,),
new SqlParameter("@UploadBy", SqlDbType.VarChar,),
new SqlParameter("@UploadDate", SqlDbType.DateTime),
new SqlParameter("@UploaderOpenId", SqlDbType.VarChar,),
new SqlParameter("@BillNo", SqlDbType.VarChar,),
new SqlParameter("@BillAmount", SqlDbType.Float,),
new SqlParameter("@Reviewedby", SqlDbType.VarChar,),
new SqlParameter("@ReviewedDate", SqlDbType.DateTime),
new SqlParameter("@ReviewedResult", SqlDbType.Bit,),
new SqlParameter("@ReviewedComment", SqlDbType.VarChar,)};
parameters[].Value = model.DocumentName;
parameters[].Value = model.DocumentPath;
parameters[].Value = model.DocumentFormatType;
parameters[].Value = model.UploadBy??"";
parameters[].Value = model.UploadDate??Convert.ToDateTime("1970/01/01");
parameters[].Value = model.UploaderOpenId??"";
parameters[].Value = model.BillNo??"";
parameters[].Value = model.BillAmount??;
parameters[].Value = model.Reviewedby??"";
parameters[].Value = model.ReviewedDate ?? Convert.ToDateTime("1970/01/01");
parameters[].Value = model.ReviewedResult;
parameters[].Value = model.ReviewedComment??""; return SQLServerHelper.ExcuteNonQuery(strSql.ToString(), CommandType.Text, parameters);
}
exec sp_executesql N'insert into WechatDocuments(DocumentName,DocumentPath,DocumentFormatType,UploadBy,UploadDate,UploaderOpenId,BillNo,BillAmount,Reviewedby,ReviewedDate,ReviewedResult,ReviewedComment) values (@DocumentName,@DocumentPath,@DocumentFormatType,@UploadBy,@UploadDate,@UploaderOpenId,@BillNo,@BillAmount,@Reviewedby,@ReviewedDate,@ReviewedResult,@ReviewedComment)',N'@DocumentName varchar(500),@DocumentPath varchar(500),@DocumentFormatType varchar(20),@UploadBy varchar(100),@UploadDate datetime,@UploaderOpenId varchar(100),@BillNo varchar(100),@BillAmount float,@Reviewedby varchar(100),@ReviewedDate datetime,@ReviewedResult bit,@ReviewedComment varchar(500)',@DocumentName='20151216072318_2511.jpg',@DocumentPath='/UploadFiles/Bill/20151216072318_2511.jpg',@DocumentFormatType=default,@UploadBy='',@UploadDate='2015-12-16 07:23:29.107',@UploaderOpenId='',@BillNo='',@BillAmount=0,@Reviewedby='',@ReviewedDate='1970-01-01 00:00:00',@ReviewedResult=0,@ReviewedComment=''
执行报错:
Msg 8178, Level 16, State 1, Line 0
The parameterized query '(@DocumentName varchar(500),@DocumentPath varchar(500),@Document' expects the parameter '@DocumentFormatType', which was not supplied.
把@DocumentFormatType=default改为@DocumentFormatType=null,就成功执行。在新添加一条数据的时候,某些字段是需要它为null的,不知道是我VS出问题了还是?
----------------------------------------------------------------------------------------------------
Error 19 The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>
错误19字符型必须是非空值类型来使用它作为参数T的泛型类型或方法的系统。空<T>
我的VS2013中,用Ado.net给SQLParameter赋值的时候,当赋值null的时候,生成的sql语句是default的更多相关文章
- oracle问题:新建了一个PDM文件,建表后生成的sql语句中含有clustered
问题描述 为了在oracle中新增表,在PDM中建表,使用其生成的sql语句,但是建表不能成功,提示 ORA-00906: 缺失左括号 原因是多了clustered 关键字 情景重现 1. 新建一个p ...
- Entity Framewrok 7beta7中不同版本sql server自动生成分页sql语句的问题
在EF中,使用linq进行分页是很方便的,假如我们有一个EMP表,结构如下: public class Emp { [Key] public Guid No { get; set; } public ...
- COMMENT方法 用于在生成的SQL语句中添加注释内容,
COMMENT方法 用于在生成的SQL语句中添加注释内容,例如: $this->comment('查询考试前十名分数') ->field('username,score') ->li ...
- Entity Framework中查看生成的SQL语句
Entity Framework 4.0 中是这样的,高版本的跟这个有些差异,不太一样,貌似已经到7了 using (Entities entities = new Entities()) { var ...
- 请问在 .NET Core 中如何让 Entity Framework Core 在日志中记录由 LINQ 生成的SQL语句?
using dotNET.Core; using Microsoft.Extensions.Logging; using System; using System.Collections.Generi ...
- mysql中查看ef或efcore生成的sql语句
http://www.solves.com.cn/it/sjk/MYSQL/2019-07-01/1336.html 涉及命令 1.开启general log模式 MySQL>set globa ...
- 理想中的SQL语句条件拼接方式 (二)
问题以及想要的效果,不重复叙述,如果需要的请先看 理想中的SQL语句条件拼接方式 . 效果 现在有2个类映射数据库的2张表,结构如下: public class User { public int U ...
- 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
总结一下SQL语句中引号(').quotedstr().('').format()在SQL语句中的用法 日期:2005年6月1日 作者:seasky212 总结一下SQL语句中引号(').quoted ...
- sql语句中的left join,right join,inner join的区别
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...
随机推荐
- 详解YUV与RGB数据格式-2016.01.20
参考文献 什么是I帧,P帧,B帧 图文详解YUV420数据格式 RGB565 与 RGB888的相互转换 最简单的基于FFmpeg的libswscale的示例(YUV转RGB)
- 4种kill某个用户所有进程的方法
在linux系统管理中,我们有时候需要kill掉某个用户的所有进程,初学者一般先查询出用户的所有pid,然后一条条kill掉,或者写好一个脚本,实际上方法都有现成的,这边有4种方法,我们以kill用户 ...
- CentOS 安裝 VMware Workstation / VMware Player
参考:http://www.vixual.net/blog/archives/650 序列号:1F04Z-6D111-7Z029-AV0Q4-3AEH8 注意说明:刚开始有很长的一系列协议信息,可以用 ...
- 关于解决pyinstaller2.1将.py打包成exe文件在中文目录下不能执行的问题
关于解决pyinstaller2.1将.py打包成exe文件在中文目录下不能执行的问题 这个问题困扰我好久了,今天终于非常偶然的在http://www.v2ex.com/t/113856#reply1 ...
- JavaScript空判断
if(backInfo != "" && backInfo != null && typeof(backInfo)!="undefined ...
- [视频]MAC OS 技巧之如何更新及重装MAC系统
mac os是当今最好用的桌面操作系统,但再好的系统也有新版本发布的一天,或者被极客的你尝试各种设置而配置混乱了,这时我们就要进行系统更新或者重装了. 系统更新 Mac OS有新版本推出时,会自动在A ...
- Winform菜单之ContextMenuStrip
ContextMenuStrip实际就是上下文菜单,就是右键单击某个窗体或者控件后出来的菜单. 从工具栏里拖一个出来放在窗口上就行 然后进行一系列的设置,设置方法跟前面的MenuStrip基本是一样的 ...
- centos6.7下网络设置
vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0"BOOTPROTO="static" # ...
- UITableView去除空白cell上多余separator
具体的效果可以参考微信ios7版的UITableview 它最后一行cell的separator是顶到最左边的 首先设置tableFooterView _messageTableview.tableF ...
- web app 开发
去除手机浏览器标签默认高亮边框 -webkit-tap-highlight-color 属性 属性描述:这个属性可以指设置透明度.如果未设置透明度,iOS上的Safari会给予颜色一个默认的透明度.把 ...