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