The stored procedure here is stored procedure under SQL Server, because tofu is not using the stored procedure, so tofu in the example
Using the SQL2K, it is estimated that it should be the same under Oracle, you are welcome to discuss this problem together with tofu
We know that there is a parameter in the stored procedure that is called output, and he can pass parameters to each other in different stored procedures, when using output
Be aware of the following situation
The OUTPUT variable must be defined when the table is created and the variable is used. Parameter names and variable names do not necessarily match, but data types and parameter positions must match
We create one of the simplest stored procedures
CREATE PROCEDURE Test
(@subject Varchar () Output)
As
Select @subject = ' Tofu production is fine '
Go
But how do you get back the parameters? White thought of the solution, and then finally on the SQL AnaLyzer on the inspiration,
DECLARE @aa Varchar (10)
Execute test @aa output
Select Aa= @aa
Based on this, we can use the ado+ processing function in asp.net to realize our idea, and finally pass SqlDataReader as
Select statement to get output, the complete program is as follows.
<%@ Import namespace= "System.IO"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<script language= "C #" runat=server>
protected void Page_Load (Object Src, EventArgs E) {
SqlDataReader DBRead;
SQLCommand Dbcomm;
String strSQL;
String strconn;
SqlConnection Conn;
Hashtable cfg=new Hashtable ();
CFG = (Hashtable) context.getconfig ("appsettings");
strconn=cfg["Conn"]. ToString ();
conn = new SqlConnection (strconn);
Strsql= "DECLARE @aa Varchar (a) \nexecute test @aa output\nselect aa= @aa";
Dbcomm = new SQLCommand (strSQL, conn);
DbComm.ActiveConnection.Open ();
Dbcomm.execute (out DBRead);
Dbread.read ();
ShowMsg. text=dbread["AA"]. ToString ();
}
</script>
<title> Test Stored Procedures </title>
<body>
<asp:label id=showmsg runat=server/>
</body>
In fact, tofu in the actual application of the output parameters are generally rarely used, tofu is generally used in this way:
The contents of the stored procedure are as follows:
CREATE PROCEDURE Test
As
Select @subject = ' Tofu production is fine '
Select Aa= @subject
Go
is to use Select at the end of the stored procedure to return the stored procedure to a collection of records, and then we can put the stored procedure
As a SELECT statement to handle, so that the ASP.net SQL statement becomes a
strsql= "Test";
Everything else changes, and the same effect can be achieved.