c# - Invalid string or buffer length when inserting null in byte type field -
i next exception when inserting :
error [hy090] [informix .net provider]invalid string or buffer length.
when
obj.request_file = null;//of byte[] type
using (ifxconnection con = new ifxconnection(configurationsettings.appsettings["con1"].tostring())) { con.open(); stringbuilder cmdtxt = new stringbuilder(); cmdtxt.append(" insert request_data(req_ser, req_year, req_date, req_emp_type, req_emp_num, req_emp_name, person_type,person_num,person_name,about_person,other_description,main_code , year,req_desc, login_num , req_title,request_file) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) "); int maxfollowserial = get_max_followserial(int.parse(obj.requestyear.tostring())) + 1; ifxcommand myifxcmd = new ifxcommand(cmdtxt.tostring(), con); myifxcmd.commandtype = commandtype.text; myifxcmd.parameters.clear(); myifxcmd.parameters.add("req_ser", maxfollowserial.tostring()); myifxcmd.parameters.add("req_year", obj.requestyear.tostring()); myifxcmd.parameters.add("req_date", obj.requestdate.tostring().split(' ')[0]); myifxcmd.parameters.add("req_emp_type", obj.requestemptype.tostring().trim()); myifxcmd.parameters.add("req_emp_num", obj.requestempnum.tostring().trim()); myifxcmd.parameters.add("req_emp_name", obj.requestempname.tostring().trim()); myifxcmd.parameters.add("person_type", obj.persontype.tostring().trim()); myifxcmd.parameters.add("person_num", obj.personnum.tostring().trim()); myifxcmd.parameters.add("person_name", obj.personname.tostring().trim()); myifxcmd.parameters.add("about_person", obj.aboutperson.tostring().trim()); myifxcmd.parameters.add("other_description", obj.otherdescription.tostring().trim()); myifxcmd.parameters.add("main_code", obj.maincode.tostring()); myifxcmd.parameters.add("year", obj.year.tostring()); myifxcmd.parameters.add("req_desc", obj.requestdescription.tostring().trim()); myifxcmd.parameters.add("login_num", obj.loginnum.tostring()); myifxcmd.parameters.add("req_title", obj.title.tostring()); myifxcmd.parameters.add("request_file", obj.request_file); int affectedrow = myifxcmd.executenonquery(); con.close(); con.dispose(); if (affectedrow > 0) homecoming maxfollowserial; else homecoming affectedrow; }
try this:
if(obj.request_file != null) myifxcmd.parameters.add("request_file", obj.request_file); else myifxcmd.parameters.add("request_file", dbnull.value);
c# asp.net null byte informix
No comments:
Post a Comment