/// <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. AX 利用windows粘贴板功能实现批量数据快速导出EXCEL

    static void test(Args _args) { int lineNum; int titleLines; SysExcelApplication excel; SysExcelWorkb ...

  2. linux进程状态

    系统维护的时候难免会遇到进程的状态的查询和管理,到底什么是R,有的是S,有的还是S+呢?一直有些混沌的问题,今天细细的来总结一下: ps是用来报告系统中程序执行状况的命令这个是无可厚非的,linux进 ...

  3. iOS中僵尸对象的实现方法

    什么是僵尸对象?所谓僵尸,就是过度释放的对象.在ios开发中,僵尸对象对于开发人员调试程序来说很有用.我们通常将NSZombieEnabled环境变量设置为YES来打开僵尸对象,但这会导致所有的对象都 ...

  4. 对于返回void类型的asyc的异步方法,如何修改,能使用await

    下面是使用WebClinet 获取百度首页的html代码,一般的写法如下: private void Button_Click(object sender, RoutedEventArgs e) { ...

  5. 必须会的SQL语句(八)数据库的完整性约束

    实体完整性 1.建表时定义主键   Create table 表名    (         Sno int identity(1,1),         Sname nvarchar(20),    ...

  6. 【转载】UML用例图

    用例图主要用来描述“用户.需求.系统功能单元”之间的关系.它展示了一个外部用户能够观察到的系统功能模型图. [用途]:帮助开发团队以一种可视化的方式理解系统的功能需求. 用例图所包含的元素如下: 1. ...

  7. Ubuntu点滴--apt-get update和upgrade的作用

    update update is used to resynchronize the package index files from their sources. The indexes of av ...

  8. 破解金盘gdlisxp系统

    1.现在要破解的金盘gdlisxp系统版本 2.首先在你电脑上要有脱壳工具AspackDie,和OllyDBG动态调试工具,电脑上装好金盘软件. 3.用AspackDie进行对金盘应用程序脱壳处理,生 ...

  9. ThinkPHP实现联动菜单;

    联动菜单,首先给你看看前端是怎么写的:

  10. 射击比赛 (POJ 1719) 题解

    [问题描述] 我们假设射击的目标是一个由R*C(2≤R≤C≤ 1000)个小方格组成的矩形网格.网格中每一列恰有2个白色的小方格和R-2个黑色的小方格.定义网格的行从顶至底编号为1~R,列从左至右编号 ...