Oracle stored procedure call in C#
-
Hi..i'm write following pl sql procedure to save data record.i have created a table called SETUP_TAB. i want to add to data from a datagridview in a form.can anyone please tell me how to do it. PROCEDURE Insert___ ( id_ OUT VARCHAR2, version_ OUT VARCHAR2, rec_ IN OUT SETUP_TAB%ROWTYPE, attribute_ IN OUT VARCHAR2 ) i have write following C# code also.but it gives "Invalid parameter binding" exception. OracleConnection conn = new OracleConnection(); String str = "Data source=****;user ID=****;Password=****;"; conn.ConnectionString = str; OracleCommand cmd = new OracleCommand("PROJX_INTEGRATION_SETUP.Insert___",conn); cmd.CommandType = CommandType.StoredProcedure; OracleParameter datarow = new OracleParameter(); datarow.ParameterName = "newrec_"; datarow.OracleDbType = OracleDbType.Raw; datarow.Direction = ParameterDirection.InputOutput; datarow.Value = this.dataGridView1.Rows[0]; cmd.Parameters.Add(datarow); OracleParameter attr = new OracleParameter(); attr.ParameterName = "attr_"; attr.OracleDbType = OracleDbType.Varchar2; attr.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(attr); OracleParameter o1 = new OracleParameter(); o1.ParameterName = "objid_"; o1.OracleDbType = OracleDbType.Varchar2; o1.Direction = ParameterDirection.Output; cmd.Parameters.Add(o1); OracleParameter o2 = new OracleParameter(); o2.ParameterName = "objversion_"; o2.OracleDbType = OracleDbType.Varchar2; o2.Direction = ParameterDirection.Output; cmd.Parameters.Add(o2); try { conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } catch (OracleException ex) { MessageBox.Show(ex.Message, "Oracle Exception"); }
-
Hi..i'm write following pl sql procedure to save data record.i have created a table called SETUP_TAB. i want to add to data from a datagridview in a form.can anyone please tell me how to do it. PROCEDURE Insert___ ( id_ OUT VARCHAR2, version_ OUT VARCHAR2, rec_ IN OUT SETUP_TAB%ROWTYPE, attribute_ IN OUT VARCHAR2 ) i have write following C# code also.but it gives "Invalid parameter binding" exception. OracleConnection conn = new OracleConnection(); String str = "Data source=****;user ID=****;Password=****;"; conn.ConnectionString = str; OracleCommand cmd = new OracleCommand("PROJX_INTEGRATION_SETUP.Insert___",conn); cmd.CommandType = CommandType.StoredProcedure; OracleParameter datarow = new OracleParameter(); datarow.ParameterName = "newrec_"; datarow.OracleDbType = OracleDbType.Raw; datarow.Direction = ParameterDirection.InputOutput; datarow.Value = this.dataGridView1.Rows[0]; cmd.Parameters.Add(datarow); OracleParameter attr = new OracleParameter(); attr.ParameterName = "attr_"; attr.OracleDbType = OracleDbType.Varchar2; attr.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(attr); OracleParameter o1 = new OracleParameter(); o1.ParameterName = "objid_"; o1.OracleDbType = OracleDbType.Varchar2; o1.Direction = ParameterDirection.Output; cmd.Parameters.Add(o1); OracleParameter o2 = new OracleParameter(); o2.ParameterName = "objversion_"; o2.OracleDbType = OracleDbType.Varchar2; o2.Direction = ParameterDirection.Output; cmd.Parameters.Add(o2); try { conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } catch (OracleException ex) { MessageBox.Show(ex.Message, "Oracle Exception"); }
Parameter names in your procedure and
OracleParameter
instance should match. Also you need to preserve the order in which parameters are added.Navaneeth How to use google | Ask smart questions
-
Parameter names in your procedure and
OracleParameter
instance should match. Also you need to preserve the order in which parameters are added.Navaneeth How to use google | Ask smart questions
thank you for reply my post.i have done that in your way.but still it gives following exception. :( :confused: "Invalid parameter binding Parameter name: rec_" here is my modified code. OracleParameter rec_ = new OracleParameter(); rec_.ParameterName = "rec_"; rec_.OracleDbType = OracleDbType.Raw; rec_.Direction = ParameterDirection.InputOutput; rec_.Value = this.dataGridView1.Rows[0]; cmd.Parameters.Add(rec_);
-
thank you for reply my post.i have done that in your way.but still it gives following exception. :( :confused: "Invalid parameter binding Parameter name: rec_" here is my modified code. OracleParameter rec_ = new OracleParameter(); rec_.ParameterName = "rec_"; rec_.OracleDbType = OracleDbType.Raw; rec_.Direction = ParameterDirection.InputOutput; rec_.Value = this.dataGridView1.Rows[0]; cmd.Parameters.Add(rec_);
As I said, parameters should be in the order which they have written in the procedure. So first
id_
thenversion_
etc should come.rec_
should be the 3rd parameter.Navaneeth How to use google | Ask smart questions
-
As I said, parameters should be in the order which they have written in the procedure. So first
id_
thenversion_
etc should come.rec_
should be the 3rd parameter.Navaneeth How to use google | Ask smart questions
yes..i have done that way..but still it gives same result.:confused: PROCEDURE Insert___ ( id_ OUT VARCHAR2, version_ OUT VARCHAR2, rec_ IN OUT PROJX_INTEGRATION_SETUP_TAB%ROWTYPE, attribute_ IN OUT VARCHAR2 ) =========================================================== OracleParameter id_ = new OracleParameter(); id_.ParameterName = "id_"; id_.OracleDbType = OracleDbType.Varchar2; id_.Direction = ParameterDirection.Output; cmd.Parameters.Add(id_); OracleParameter version_ = new OracleParameter(); version_.ParameterName = "version_"; version_.OracleDbType = OracleDbType.Varchar2; version_.Direction = ParameterDirection.Output; cmd.Parameters.Add(version_); OracleParameter rec_ = new OracleParameter(); rec_.ParameterName = "rec_"; rec_.OracleDbType = OracleDbType.Raw; rec_.Direction = ParameterDirection.InputOutput; rec_.Value = this.dataGridView1.Rows[0]; cmd.Parameters.Add(rec_); OracleParameter attribute_ = new OracleParameter(); attribute_.ParameterName = "attribute_"; attribute_.OracleDbType = OracleDbType.Varchar2; attribute_.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(attribute_);
-
yes..i have done that way..but still it gives same result.:confused: PROCEDURE Insert___ ( id_ OUT VARCHAR2, version_ OUT VARCHAR2, rec_ IN OUT PROJX_INTEGRATION_SETUP_TAB%ROWTYPE, attribute_ IN OUT VARCHAR2 ) =========================================================== OracleParameter id_ = new OracleParameter(); id_.ParameterName = "id_"; id_.OracleDbType = OracleDbType.Varchar2; id_.Direction = ParameterDirection.Output; cmd.Parameters.Add(id_); OracleParameter version_ = new OracleParameter(); version_.ParameterName = "version_"; version_.OracleDbType = OracleDbType.Varchar2; version_.Direction = ParameterDirection.Output; cmd.Parameters.Add(version_); OracleParameter rec_ = new OracleParameter(); rec_.ParameterName = "rec_"; rec_.OracleDbType = OracleDbType.Raw; rec_.Direction = ParameterDirection.InputOutput; rec_.Value = this.dataGridView1.Rows[0]; cmd.Parameters.Add(rec_); OracleParameter attribute_ = new OracleParameter(); attribute_.ParameterName = "attribute_"; attribute_.OracleDbType = OracleDbType.Varchar2; attribute_.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(attribute_);
I have sorted out my problem.thanks for all , special thank for "navaneeth" ... :laugh: :laugh: