Add or modify nullable non-string type data to the ORALCE database using the parameter method

Source: Internet
Author: User

Sometimes when you do not use an ORM framework, either by hand or by code generator-generated INSERT statements with parameters, such as

/// <summary>        ///add a piece of data/// </summary>         Public Static BOOLAdd (Model.imginfo Model) {StringBuilder strSQL=NewStringBuilder (); Strsql.append ("INSERT INTO Imginfo ("); Strsql.append ("Id,rycrjlxxid,dsp,xp,inserttime,scip)"); Strsql.append ("VALUES ("); Strsql.append (": Id,:rycrjlxxid,:D Sp,:xp,:inserttime,:scip)"); oracleparameter[] Parameters= {                    NewOracleParameter (": ID", Oracletype.varchar, +),                    NewOracleParameter (": Rycrjlxxid", Oracletype.varchar, +),                    NewOracleParameter (":D SP", Oracletype.blob),NewOracleParameter (": XP", Oracletype.blob),NewOracleParameter (": Inserttime", Oracletype.datetime),NewOracleParameter (": SCIP", Oracletype.varchar, +)}; parameters[0]. Value =model.id; parameters[1]. Value =model.            Rycrjlxxid; parameters[2]. Value =model.            DSP; parameters[3]. Value =model.            XP; parameters[4]. Value =model.            Inserttime; parameters[5]. Value =model.            SCIP; returnDbhelpertarget.executecommand (strsql.tostring (), parameters); }

At first look at this code there is no problem, the parameters are bound, but the execution of the error, it is probably mean that some parameters are not bound data, how can this happen?

Because the object's DSP and XP and Inserttime are all non-mandatory in this example, the problem is that sometimes when assigning values to an object, these fields are not assigned, which is the default NULL, but Oracle does not assume that you have given the parameter binding value. Here's a solution to define an empty non-string type field as an object type.

For example

[Serializable] Public Partial classImginfo { PublicImginfo () {}#regionModelPrivate string_id; Private string_rycrjlxxid; Private Object_DSP; Private Object_xp; Private Object_inserttime;  Public stringSCIP {Get;Set; } /// <summary>        ///         /// </summary>         Public stringID {Set{_id=value;} Get{return_id;} }         Public stringRycrjlxxid {Set{_rycrjlxxid=value;} Get{return_rycrjlxxid;} }          Public ObjectDSP {Set{_dsp=value;} Get{return_DSP;} }         Public ObjectXP {Set{_xp=value;} Get{return_xp;} }            Public ObjectInserttime {Set{_inserttime=value;} Get{return_inserttime;} }

When assigning a value to the object, this special field is not empty when the corresponding type of data, if it is empty, the assignment is DBNull.Value, so that the execution again, found no longer an error.

Add or modify nullable non-string type data to the ORALCE database using the parameter method

Related Article

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.