SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> " /> 亚洲日本va,尤物网精品视频,国产成人综合av

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

.Net 調用存儲過程取到return的返回值

1. 存儲過程

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= alter PROCEDURE GetOrderLine @orderId varchar(50) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; select * from orderLine where OrderId = @orderId; return 123; END GO

 注意 存儲過程只能返回 int 類型,如果返回一個字符串 ,將會報類型轉化錯誤

2 后臺調用

DataTable dt = new DataTable(); string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["BLL.Properties.Settings.ShoppingDBConnectionString"].ToString(); using(SqlConnection conn= new SqlConnection(connStr)){ string callName = "GetOrderLine"; using (SqlCommand command = new SqlCommand(callName, conn)) { command.CommandType = CommandType.StoredProcedure; SqlParameter[] sps = { new SqlParameter("@orderId",SqlDbType.VarChar,50) , new SqlParameter("@return",SqlDbType.Int) //注冊返回值類型 }; sps[0].Value = "43c7cf15-6b2f-4d18-92b2-dbe827f30dfc"; sps[1].Direction = ParameterDirection.ReturnValue; //返回參數類型 command.Parameters.AddRange(sps); using(SqlDataAdapter sda =new SqlDataAdapter()){ sda.SelectCommand = command; sda.Fill(dt); //Console.WriteLine(sda.GetFillParameters()[1].Value); Console.WriteLine(sps[1].Value); //取到返回的值 } } } if(dt.Rows.Count>0){ for (int i = 0; i < dt.Rows.Count;i++ ) { Console.WriteLine(dt.Rows[i]["ProductId"]+":"+dt.Rows[i]["ProductPrice"]+":"+dt.Rows[i]["ProductCount"]); } } Console.ReadLine();

AspNet技術.Net 調用存儲過程取到return的返回值,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 延川县| 宿迁市| 栾川县| 泾源县| 武安市| 栖霞市| 石楼县| 锦州市| 饶河县| 井冈山市| 定州市| 威海市| 黎城县| 武隆县| 乌兰察布市| 井研县| 赤水市| 宝坻区| 望都县| 阳谷县| 南充市| 建始县| 山东省| 芷江| 西盟| 文成县| 鞍山市| 博乐市| 白玉县| 湖口县| 右玉县| 赤壁市| 通河县| 宣威市| 舞阳县| 临海市| 永春县| 乡城县| 岚皋县| 思南县| 平果县|