When creating a stored procedure with output parameters and returned values --- a low-level error, stored procedure ---

Source: Internet
Author: User

When creating a stored procedure with output parameters and returned values --- a low-level error, stored procedure ---

Exception Handling Summary-database http://www.cnblogs.com/dunitian/p/4522990.html Series

Post will be in the blog to start update: http://dnt.dkill.net/Article/Detail/313

Error. How to execute it without the desired effect (return is lost. What else is there ???!!!)

After processing:

If exists (select * from sysobjects where name = 'usp _ AllPmsTest ') drop proc extends proc attributes @ cityName nvarchar (30), @ id int outputasbegininsert into ShopModelBak values (@ cityName, 1, 1) set @ id = @ identityselect CPName, CName, SName, MType, MName, Mprice from ShopMenu inner join ShopModel on ShopMenu. MShopId = ShopModel. SIdinner join View_CityData on ShopMenu. MCityId = CIdwhere CName = @ cityNamereturn (select count (1) from ShopMenu) endgodeclare @ total int, @ id intexec @ total = usp_AllPmsTest 'binhu ', @ id outputselect @ id, @ total

 

ADO. Net

Var pms = new SqlParameter [] {new SqlParameter ("@ cityName", "binhu district"), new SqlParameter ("@ id", SqlDbType. int), new SqlParameter ("@ total", SqlDbType. int)}; pms [1]. direction = ParameterDirection. output; pms [2]. direction = ParameterDirection. returnValue; var list = SQLHelper. executeReader <ShopMenu> ("usp_AllPmsTest", CommandType. storedProcedure, pms); foreach (var item in list) {Console. writeLine (item. MName + "" + item. MPrice);} Console. writeLine ("the inserted ID is {0}, total {1} pieces of data", pms [1]. value, pms [2]. value );

Related Articles: http://www.cnblogs.com/dunitian/p/5362528.html

 

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.