/// <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的更多相关文章

  1. oracle问题:新建了一个PDM文件,建表后生成的sql语句中含有clustered

    问题描述 为了在oracle中新增表,在PDM中建表,使用其生成的sql语句,但是建表不能成功,提示 ORA-00906: 缺失左括号 原因是多了clustered 关键字 情景重现 1. 新建一个p ...

  2. Entity Framewrok 7beta7中不同版本sql server自动生成分页sql语句的问题

    在EF中,使用linq进行分页是很方便的,假如我们有一个EMP表,结构如下: public class Emp { [Key] public Guid No { get; set; } public ...

  3. COMMENT方法 用于在生成的SQL语句中添加注释内容,

    COMMENT方法 用于在生成的SQL语句中添加注释内容,例如: $this->comment('查询考试前十名分数') ->field('username,score') ->li ...

  4. Entity Framework中查看生成的SQL语句

    Entity Framework 4.0 中是这样的,高版本的跟这个有些差异,不太一样,貌似已经到7了 using (Entities entities = new Entities()) { var ...

  5. 请问在 .NET Core 中如何让 Entity Framework Core 在日志中记录由 LINQ 生成的SQL语句?

    using dotNET.Core; using Microsoft.Extensions.Logging; using System; using System.Collections.Generi ...

  6. mysql中查看ef或efcore生成的sql语句

    http://www.solves.com.cn/it/sjk/MYSQL/2019-07-01/1336.html 涉及命令 1.开启general log模式 MySQL>set globa ...

  7. 理想中的SQL语句条件拼接方式 (二)

    问题以及想要的效果,不重复叙述,如果需要的请先看 理想中的SQL语句条件拼接方式 . 效果 现在有2个类映射数据库的2张表,结构如下: public class User { public int U ...

  8. 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法

    总结一下SQL语句中引号(').quotedstr().('').format()在SQL语句中的用法 日期:2005年6月1日 作者:seasky212 总结一下SQL语句中引号(').quoted ...

  9. sql语句中的left join,right join,inner join的区别

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...

随机推荐

  1. MFC启动和关闭线程

    1. 启动线程: CWinThread* AfxBeginThread( 线程函数,this ); 2.通常导致线程终止的两种情况是:控制函数退出或不允许线程完成运行.如果字处理器使用后台打印线程,若 ...

  2. ionic pull to refresh 下拉更新頁面

    有些項目都用到了下拉更新頁面的效果: 1. 在index.html 中添加ion-refresher 指令 且在我們需要更新內容的外面 添加 如 <ion-refresher pulling-t ...

  3. PAT1038. Recover the Smallest Number

    //意识到一个重要错误,一直以为atoi,itoa是windows独有的,linux下不可用,直到刚刚... //string+=比strcat好用多了,字符比较也方便的多,但是用scanf读入str ...

  4. 安装package.js

  5. 打地鼠游戏ios源码

    打地鼠游戏源码,游戏是一款多关卡基于cocos2d的iPad打地鼠游戏源码,这也是一款高质量的打地鼠游戏源码,可以拥有逐步上升的关卡的设置,大家可以在关卡时设置一些商业化的模式来盈利的,非常完美的一款 ...

  6. ASP.NET MVC5 入门

    参考资料<ASP.NET MVC5 高级编程>第5版 第1章 入门 1.1 ASP.NET MVC 简介 ASP.NET MVC是一种构建Web 应用程序的框架,它将一般的MVC(Mode ...

  7. 观察者(observer)设计模式

    转载:http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx 假设我们有个高档的热水器,我们给它 ...

  8. [leetcode]_Climbing Stairs

    我敢保证这道题是在今早蹲厕所的时候突然冒出的解法.第一次接触DP题,我好伟大啊啊啊~ 题目:一个N阶的梯子,一次能够走1步或者2步,问有多少种走法. 解法:原始DP问题. 思路: 1.if N == ...

  9. apache和IIS共享80端口问题

    使用apache代理功能和IIS共享80端口的解决办法. 第一步:把iis所发布的网站默认端口由80改为8080: 第二步:修改apache的httpd.conf配置文件.  首先,要让apache支 ...

  10. Js学习笔记一(鼠标事件.....)

    1.encodeURI与decodeURI()转化url为有效的url(能被识别) Url="http://news.baidu.com/p.php?id='测试'&姓名=hkui& ...