In my VS2013, when I assign a value to SqlParameter with ADO, the generated SQL statement is the default when I assign null.

Source: Internet
Author: User

/// <summary>        ///add a piece of data/// </summary>         Public BOOLAdd (model.wechatdocuments Model) {StringBuilder strSQL=NewStringBuilder (); 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= {                    NewSqlParameter ("@DocumentName", SqlDbType.VarChar, -),                    NewSqlParameter ("@DocumentPath", SqlDbType.VarChar, -),                    NewSqlParameter ("@DocumentFormatType", SqlDbType.VarChar, -),                    NewSqlParameter ("@UploadBy", SqlDbType.VarChar, -),                    NewSqlParameter ("@UploadDate", Sqldbtype.datetime),NewSqlParameter ("@UploaderOpenId", SqlDbType.VarChar, -),                    NewSqlParameter ("@BillNo", SqlDbType.VarChar, -),                    NewSqlParameter ("@BillAmount", Sqldbtype.float,8),                    NewSqlParameter ("@Reviewedby", SqlDbType.VarChar, -),                    NewSqlParameter ("@ReviewedDate", Sqldbtype.datetime),NewSqlParameter ("@ReviewedResult", Sqldbtype.bit,1),                    NewSqlParameter ("@ReviewedComment", SqlDbType.VarChar, -)}; 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[Ten]. Value =model.            Reviewedresult; parameters[ One]. Value = model. Reviewedcomment??""; returnSqlserverhelper.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 ($), @DocumentPath varchar (500), @ documentFormatType varchar, @UploadBy varchar, @UploadDate datetime, @UploaderOpenId varchar, @BillNo varchar, @BillAmount float, @Reviewedby varchar, @ReviewedDate datetime, @ReviewedResult bit,@ Reviewedcomment varchar (+) ', @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 = '

Execution Error:

MSG 8178, Level A, State 1, line 0
The parameterized query ' (@DocumentName varchar, @DocumentPath varchar, @Document ' expects the parameter ' @ documentFormatType ', which was not supplied.

Change the @documentformattype=default to @documentformattype=null and execute it successfully. When adding a new piece of data, some fields need to be null, do not know if it is me vs.

----------------------------------------------------------------------------------------------------

Error the type ' string ' must is a non-nullable value type in order to use it as parameter ' T ' in the generic type or me Thod ' system.nullable<t>

The error 19 character type must be a non-null value type to use as a system for the generic type or method of the parameter T. Air <T>

In my VS2013, when I assign a value to SqlParameter with ADO, the generated SQL statement is the default when I assign null.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.