无法从存储过程中获取价值

我正在尝试从存储过程中获取值,下面是我的代码


SqlConnection connection = new SqlConnection("");

connection.Open();

DataTable timeZoneDt = new DataTable();

var sqlCommand = new SqlCommand("GetTimeZoneGMT", connection);

sqlCommand.CommandType = CommandType.StoredProcedure;

sqlCommand.Parameters.Add("@TimeZone", SqlDbType.NVarChar).Value = "Asia/Kuala_Lumpur";

//timeZoneDt.Load(sqlCommand.ExecuteReader());

//new SqlDataAdapter(sqlCommand).Fill(timeZoneDt);


var reader2 = sqlCommand.ExecuteReader();



while (reader2.Read())

{

    var ID = int.Parse(reader2[0].ToString());

}

connection.Close();

以下是我的存储过程,


/****** Object:  StoredProcedure [dbo].[GetTimeZoneGMT]    Script Date: 23/4/2018 4:05:46 PM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO



ALTER PROCEDURE [dbo].[GetTimeZoneGMT]

    @TimeZone NVARCHAR(128)

AS

BEGIN

 DECLARE @timeZoneNumber as INT = -20;

 IF @TimeZone ='Pacific/Midway'

 SET @timeZoneNumber = -11

 ELSE IF @TimeZone ='Pacific/Niue'

 SET @timeZoneNumber = -11

 ELSE IF @TimeZone ='Pacific/Pago_Pago'

 SET @timeZoneNumber = -11


 RETURN @timeZoneNumber;

END

我不能全部写给大家,因为时区有400行,但是类似。


但是,当我得到我的C#代码时,它是空值,为什么呢?代码有什么问题

http://img1.mukewang.com/60965fd600014adb07110392.jpg

幕布斯7119047
浏览 137回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP