问题描述
我想在存储过程的帮助下在Employees(Empid,名字,姓氏,工资)表中插入数据。
我想要这个存储过程调用按钮点击后面的asp.net代码。
我正在使用oracle数据库。
如何创建存储过程并从中调用它我的代码背后。
谢谢
-Akshay
Hi,
I want to insert a data in the table Employees(Empid,first name,lastname,salary) with the help of stored procedure.
I want this stored proc called on button click from asp.net code behind.
I am using oracle database.
How can i go about in creating the stored proc and call it from my code behind.
Thanks
-Akshay
推荐答案
create package in oracle
create procedure in that package
创建或替换包装体SCHEMA.TEST_PKG
AS
程序TEST_PROC(VARCHAR2中的P_EMP_ID,VARCHAR2中的P_FISRT_NAME,VARCHAR2中的P_LAST_NAME,P_SALARY中的数字,P_TRANSACTION_STATUS OUT VARCHAR2)
AS
BEGIN
INSERT INTO EMPLOYEE(EMP_ID,FISRT_NAME,LAST_NAME,SALARY)
VALUES(P_EMP_ID,P_FISRT_NAME,P_LAST_NAME,P_SALARY);
P_TRANSACTION_STATUS:= 'SUCCESS';
END;
CREATE OR REPLACE PACKAGE BODY SCHEMA.TEST_PKG
AS
PROCEDURE TEST_PROC( P_EMP_ID IN VARCHAR2,P_FISRT_NAME IN VARCHAR2,P_LAST_NAME IN VARCHAR2,P_SALARY IN NUMBER, P_TRANSACTION_STATUS OUT VARCHAR2)
AS
BEGIN
INSERT INTO EMPLOYEE(EMP_ID,FISRT_NAME,LAST_NAME,SALARY)
VALUES (P_EMP_ID ,P_FISRT_NAME,P_LAST_NAME,P_SALARY);
P_TRANSACTION_STATUS := ‘SUCCESS’;
END;
In web code use microsoft enterprise libarry as ADO.net connectivity
and call above procedure from code behind
public string insert_data(string id, string name, string last_name, int salary)
{
string transactionstatus = string.Empty;
if (db != null)
{
cmd = (OracleCommand)db.GetStoredProcCommand("TEST_PKG.TEST_PROC");
cmd.Parameters.Add("P_EMP-ID", OracleType.VarChar, 2000).Value = id;
cmd.Parameters.Add("P_FIRST_NAME",OracleType.VarChar, 2000).Value = name;
cmd.Parameters.Add("P_LAST_NAME", OracleType.VarChar, 2000).Value = last_name;
cmd.Parameters.Add("P_SALARY", OracleType.number, 2000).Value = salary;
cmd.Parameters.Add("P_TRANSACTION_STATUS", OracleType.VarChar, 2000).Direction = ParameterDirection.Output;
int i = db.ExecuteNonQuery(cmd);
if (i <= 0)
{
transactionstatus = "FAIL";
}
return transactionstatus = cmd.Parameters["P_TRANSACTION_STATUS"].Value.ToString();
}
return transactionstatus;
}
这篇关于从存储过程中将数据插入到oracle中,该按钮点击后面的asp.net代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!