博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我的VS2013中,用Ado.net给SQLParameter赋值的时候,当赋值null的时候,生成的sql语句是default...
阅读量:4963 次
发布时间:2019-06-12

本文共 4036 字,大约阅读时间需要 13 分钟。

///         /// 增加一条数据        ///         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,500),                    new SqlParameter("@DocumentPath", SqlDbType.VarChar,500),                    new SqlParameter("@DocumentFormatType", SqlDbType.VarChar,20),                    new SqlParameter("@UploadBy", SqlDbType.VarChar,100),                    new SqlParameter("@UploadDate", SqlDbType.DateTime),                    new SqlParameter("@UploaderOpenId", SqlDbType.VarChar,100),                    new SqlParameter("@BillNo", SqlDbType.VarChar,100),                    new SqlParameter("@BillAmount", SqlDbType.Float,8),                    new SqlParameter("@Reviewedby", SqlDbType.VarChar,100),                    new SqlParameter("@ReviewedDate", SqlDbType.DateTime),                    new SqlParameter("@ReviewedResult", SqlDbType.Bit,1),                    new SqlParameter("@ReviewedComment", SqlDbType.VarChar,500)};            parameters[0].Value = model.DocumentName;            parameters[1].Value = model.DocumentPath;            parameters[2].Value = model.DocumentFormatType;            parameters[3].Value = model.UploadBy??"";            parameters[4].Value = model.UploadDate??Convert.ToDateTime("1970/01/01");            parameters[5].Value = model.UploaderOpenId??"";            parameters[6].Value = model.BillNo??"";            parameters[7].Value = model.BillAmount??0;            parameters[8].Value = model.Reviewedby??"";            parameters[9].Value = model.ReviewedDate ?? Convert.ToDateTime("1970/01/01");            parameters[10].Value = model.ReviewedResult;            parameters[11].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> 

转载于:https://www.cnblogs.com/sen068/p/5050036.html

你可能感兴趣的文章
iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
查看>>
toad for oracle中文显示乱码
查看>>
SQL中Group By的使用
查看>>
错误org/aopalliance/intercept/MethodInterceptor解决方法
查看>>
Pylint在项目中的使用
查看>>
使用nginx做反向代理和负载均衡效果图
查看>>
access remote libvirtd
查看>>
(4) Orchard 开发之 Page 的信息存在哪?
查看>>
ASP.NET中 GridView(网格视图)的使用前台绑定
查看>>
深入了解Oracle ASM(二):ASM File number 1 文件目录
查看>>
Boosting(提升方法)之AdaBoost
查看>>
Binding object to winForm controller through VS2010 Designer(通过VS2010设计器将对象绑定到winForm控件上)...
查看>>
Spring Boot实战笔记(二)-- Spring常用配置(Scope、Spring EL和资源调用)
查看>>
SwaggerUI+SpringMVC——构建RestFul API的可视化界面
查看>>
springmvc怎么在启动时自己执行一个线程
查看>>
C# 通知机制 IObserver<T> 和 IObservable<T>
查看>>
Code of Conduct by jsFoundation
查看>>
C#小练习ⅲ
查看>>
电源防反接保护电路
查看>>
arraylist
查看>>