How to obtain the value in the stored procedure in aspx (answer the jspfuns question)

Source: Internet
Author: User

The stored procedure is stored in SQL Server. Because no stored procedure is used for tofu
SQL2K is used. It is estimated that the same should be true in Oracle. You are welcome to discuss this issue with bean curd.
We know that there is an output parameter in the stored procedure. It can pass parameters in different stored procedures.
Pay attention to the following situations:

The OUTPUT variable must be defined when the table is created and used. The parameter name and variable name do not have to match, but the data type and parameter location must match
Create a simple Stored Procedure
Create procedure test
(@ Subject Varchar (15) Output)
AS
Select @ subject = tofu is made of excellent products
GO
But how can we get the return parameter? Finally, I was inspired by SQL AnaLyzer,
DECLARE @ aa Varchar (10)
Execute test @ aa output
Select aa = @ aa
Based on this, we can use the multi-statement processing function of ADO + in Asp. Net to implement our ideas. Finally, through SQLDataReader
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 (10) execute test @ aa outputselect aa = @ aa ";
DbComm = new SQLCommand (strSQL, conn );
DbComm. ActiveConnection. Open ();
DbComm. Execute (out dbRead );
DbRead. Read ();
Showmsg. Text = dbRead ["aa"]. ToString ();
}
</Script>
<Html>
<Head>
<Title> test the Stored Procedure </title>
</Head>
<Body>
<Asp: Label id = showmsg runat = server/>
</Body>
</Html>
In fact, the output parameter is rarely used in the actual application, and the bean curd is generally used in this way:
The content of the stored procedure is as follows:
Create procedure test
AS
Select @ subject = tofu is made of excellent products
Select aa = @ subject
GO
The stored procedure returns a record set using the Select statement at the end of the stored procedure. Then we can set the Stored Procedure
As a select statement, the SQL statement of asp. Net becomes
StrSQL = "test ";
Other content changes, and the same effect can be obtained.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.