異常處理彙總-資料庫系列 http://www.cnblogs.com/dunitian/p/4522990.html 後期會在博客首發更新:http://dnt.dkill.net/Article/Detail/313 錯誤如圖,怎麼執行都沒有自己想要的效果(return掉了,還有個啥???!!! ...
異常處理彙總-資料庫系列 http://www.cnblogs.com/dunitian/p/4522990.html
後期會在博客首發更新:http://dnt.dkill.net/Article/Detail/313
錯誤如圖,怎麼執行都沒有自己想要的效果(return掉了,還有個啥???!!!)
處理後:
if exists(select * from sysobjects where name='usp_AllPmsTest') drop proc usp_AllPmsTest go create proc usp_AllPmsTest @cityName nvarchar(30), @id int output as begin insert into ShopModelBak values(@cityName,1,1) set @id=@@identity select CPName,CName,SName,MType,MName,Mprice from ShopMenu inner join ShopModel on ShopMenu.MShopId=ShopModel.SId inner join View_CityData on ShopMenu.MCityId=CId where CName=@cityName return (select count(1) from ShopMenu) end go declare @total int,@id int exec @total=usp_AllPmsTest '濱湖區',@id output select @id Id,@total total
ADO.Net
var pms = new SqlParameter[] { new SqlParameter("@cityName", "濱湖區"), 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("剛纔插入的ID是:{0},總共{1}條數據", pms[1].Value, pms[2].Value);
相關文章:http://www.cnblogs.com/dunitian/p/5362528.html