【问题标题】:Error on calling procedure from oracle to C#从 oracle 到 C# 调用过程时出错
【发布时间】:2014-03-16 16:37:51
【问题描述】:

您好,我正在使用存储过程创建应用程序。我无法将数据插入表中。

我的桌子是:

SQL> create table test (name varchar2(20), qualification varchar2(10), address v
archar2(100));

Table created.

我的存储过程是

SQL> create or replace procedure inserttest (
  2  p_name test.name%TYPE,
  3  p_qualification test.qualification%TYPE,
  4  p_address test.address%TYPE)
  5  IS
  6  BEGIN
  7  INSERT INTO test (name, qualification, address)
  8  VALUES (p_name, p_qualification, p_address);
  9  COMMIT;
 10  END;
 11  /

Procedure created.

我的 C# 代码是:

protected void Button1_Click(object sender, EventArgs e)
        {
            con = new OleDbConnection("Provider=MSDAORA;Data Source=xe;Persist Security Info=True;Password=sesu;User ID=system");
            cmd.Parameters.Add("p_name", OleDbType.VarChar ).Value = TextBox1.Text;
            cmd.Parameters.Add("p_qualification", OleDbType.VarChar).Value = TextBox2.Text;
            cmd.Parameters.Add("p_address", OleDbType.VarChar).Value = TextBox3.Text;
            cmd = new OleDbCommand ("inserttest", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close(); 

        }

我无法通过 C# 插入数据。它显示:

One or more errors occurred during processing of command.
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'INSERTTEST'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

有什么问题。?如何解决?

【问题讨论】:

    标签: c# vb.net oracle stored-procedures plsqldeveloper


    【解决方案1】:

    我认为PLS-00306: wrong number or types of arguments in call to 'INSERTTEST' 因为你在表中有varchar2(20)。在代码隐藏中你提到了OleDbType.VarChar。还要检查你的存储过程数据类型并使用正确的数据类型

    在存储的peoedure中尝试这样

       create or replace procedure inserttest (
       p_name varchar2(20),
       p_qualification varchar2(20),
       p_address varchar2(20))
    IS
    BEGIN
    INSERT INTO test (name, qualification, address)
    VALUES (p_name, p_qualification, p_address);
    COMMIT;
    END;
    

    【讨论】:

      【解决方案2】:

      您可以尝试在存储过程中为参数定义静态类型:

      create or replace procedure inserttest (
          p_name          in varchar2,
          p_qualification in varchar2,
          p_address       in varchar2
      )
      IS
      BEGIN
          INSERT INTO test (name, qualification, address)
          VALUES (p_name, p_qualification, p_address);
          COMMIT;
      END;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-16
        • 1970-01-01
        • 2018-02-10
        • 2012-08-02
        • 1970-01-01
        • 2012-05-18
        相关资源
        最近更新 更多