1.1 不带参数,没有返回值

创建表

create table test
(ID number,
NAME varchar2(10),
SEX varchar2(4),
AGE number,
ADDRESS varchar2(200)
);

创建不带参数的存储过程

create or replace procedure proc1
is
begin insert into test(ID,NAME,SEX,AGE) values
(1,'moses','man',25);
commit;
end;
/

C#代码调用

protected void Button2_Click(object sender, EventArgs e)
{
        String oc = ConfigurationManager.ConnectionStrings["conn"].ToString();
        OracleConnection conn = new OracleConnection(oc);
        conn.Open();
        OracleCommand orm = conn.CreateCommand();
        orm.CommandType = CommandType.StoredProcedure;
        orm.CommandText = "proc1";
        orm.ExecuteNonQuery();
        conn.Close();
}

1.2 没有返回值的带参数的存储过程

create or replace proc2
(v_id  number,
v_name varchar2
)
is begin insert into test(id,name)
values(v_id,v_name);
commit;
end;
/

C#调用

protected void Button1_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(this.TextBox2.Text))
        {
            this.TextBox2.Text = "编号不能为空";
            this.TextBox2.Focus();
            return;

        }
        if (string.IsNullOrEmpty(this.TextBox3.Text))
        {
            this.TextBox3.Text = "姓名不能为空";
            this.TextBox3.Focus();
            return;
           

        }
       String or=ConfigurationManager.ConnectionStrings["conn"].ToString();
       OracleConnection oc = new OracleConnection(or);
       oc.Open();
       OracleCommand om = oc.CreateCommand();
       om.CommandType = CommandType.StoredProcedure;
       om.CommandText = "proc2";
       om.Parameters.Add("v_id", OracleType.Number).Direction = ParameterDirection.Input;
       om.Parameters["v_id"].Value = this.TextBox2.Text.Trim();
       om.Parameters.Add("v_name", OracleType.NVarChar).Direction = ParameterDirection.Input;
       om.Parameters["v_name"].Value = this.TextBox3.Text.Trim();
       om.ExecuteNonQuery();
       oc.Close();
    }
View Code

相关文章:

  • 2022-12-23
  • 2021-06-02
  • 2022-02-23
  • 2021-07-07
  • 2021-09-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案