Saturday, 15 June 2013

c# - ORA-01008 error-Inserting a record into Oracle DB using OleDb -



c# - ORA-01008 error-Inserting a record into Oracle DB using OleDb -

the code involves inserting record values inputted in vs 2010 oracle db using c# .the database has been created in sqlplus , upon debugging in vs ive encountered error-ora 01008. th syntax matches of default one. can point out error.

oledbconnection con = new oledbconnection(); con.connectionstring = "provider="provider";data source=xxxx;user id=usernamepassword=password"; con.open(); string insertquery = "insert checklist(id,customer,server,check_type,description,path_url,text,cat3,cat4) values (:id,:customer,:server,:check1,:description,:path1,:text1,:cat3,:cat4)"; oledbcommand cmd = new oledbcommand(insertquery, con); oledbdataadapter adapter = new oledbdataadapter(insertquery, con); cmd.parameters.add(new oledbparameter(":id", textbox9.text)); cmd.parameters.add(new oledbparameter(":customer", textbox1.text)); cmd.parameters.add(new oledbparameter(":server", textbox2.text)); cmd.parameters.add(new oledbparameter(":check1", textbox3.text)); cmd.parameters.add(new oledbparameter(":description", textbox4.text)); cmd.parameters.add(new oledbparameter(":path1", textbox5.text)); cmd.parameters.add(new oledbparameter(":text1", textbox6.text)); cmd.parameters.add(new oledbparameter(":cat3", textbox7.text)); cmd.parameters.add(new oledbparameter(":cat4", textbox8.text)); cmd.executenonquery(); response.write("registration successful"); con.close();

from oledbcommand.parameters property

the ole db .net provider not back upwards named parameters passing parameters sql statement or stored procedure called oledbcommand when commandtype set text. in case, question mark (?) placeholder must used. example:

select * customers customerid = ?

therefore, order in oledbparameter objects added oledbparametercollection must straight correspond position of question mark placeholder parameter in command text.

try ? specify parameters.

string insertquery = @"insert checklist(id,customer,server,check_type,description,path_url,text,cat3,cat4) values(?,?,?,?,?,?,?,?,?)";

your oledbdataadapter seems pointless well. inserting data. don't homecoming info maintain in oledbdataadapter.

also utilize using statement dispose oledbconnection , oledbcommand like;

using(oledbconnection con = new oledbconnection(constring)) using(oledbcommand cmd = con.createcommand()) { // set commandtext property. // define , add together parameter values. // open oledbconnection. // execute query executenonquery. }

c# oracle visual-studio-2010

No comments:

Post a Comment