asp.net the implementation code to obtain the return value of the stored procedure _ Practical Tips

Source: Internet
Author: User
1. First, we will establish a table (UserInfo).
Primary field ID, uname, upass.
2. Create a stored procedure with a return value
Copy Code code as follows:

Create proc Proc_adduserinfo
@uname varchar (50),
@upass varchar (50),
@Returnc int Output
As
Begin
Insert into Erp_user (U_name,u_pass) VALUES (@uname, @upass)
Set @Returnc = IsNull (@ @identity, 0)
End

Return value here I get the ID of the add record.
Background code:
Copy Code code as follows:

Sqlparameter[] para = new sqlparameter[]
{
New SqlParameter ("@uname", "2012"),
New SqlParameter ("@upass", "2012")
};
String Sql_para = "Dbo.proc_adduserinfo";
CommandType type=commandtype.storedprocedure;
SQLHelper SQLH = new SQLHelper ();
int ID=SQLH. Executenoquery (Sql_para,type,para);

SQLHelper:
Copy Code code as follows:

public int executenoquery (string sql,commandtype type,params SqlParameter [] Values)
{
using (SqlCommand cmd = new SqlCommand (SQL, Conn))
{
Cmd.commandtype = type;
if (values!= null)
{
cmd. Parameters.addrange (values);
}
SqlParameter retvar = cmd. Parameters.Add ("@Returnc", SqlDbType.Int);
Retvar.direction = ParameterDirection.Output;
int count = cmd. ExecuteNonQuery ();
Return (int) Retvar.value;
}
}
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.