How to get a numeric value in a stored procedure in ASPX

Source: Internet
Author: User
Tags numeric numeric value

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.

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.