我有以下stored procedure
Create Procedure [dbo].[spVerifyCustomerUserLogin]
@EmbossLine varchar(16),
@password varchar(50)
as
Select C.EmbossLine,C.EmbossName,round(CB.TotalLoading,2),round(CB.Totalredemption,2),round(CB.CardBalance,2)
from Card C inner join CardBalance CB on CB.PAN=C.EmbossLine
where
EmbossLine = @EmbossLine
and [password] = @password
and Status='E0'
我有以下VB.Net
代码来访问它:
Dim UserData As New ArrayList
Dim dr As SqlDataReader
dr = GenericDB.ExecuteSPForDataReader("spVerifyCustomerUserLogin", spParameters)
If dr.HasRows Then
dr.Read()
UserData.Add(dr.Item("EmbossLine"))
UserData.Add(dr.Item("EmbossName"))
UserData.Add(dr.Item("TotalLoading"))
UserData.Add(dr.Item("Totalredemption"))
UserData.Add(dr.Item("CardBalance"))
dr.Close()
Return UserData
End If
dr.Close()
Return UserData
问题是我的代码IndexOutOfRangeException
抛出异常
UserData.Add(dr.Item("TotalLoading"))
请注意,当我在没有 round
函数的情况下访问存储过程时,它工作正常,因此它与我的 round 函数有关。请注意,我的字段TotalLoading
、TotalRedemption
和CardBalance
属于货币类型。是因为这个吗?
不,这是因为您在 totalLoading 列中使用了一个函数并且没有为其添加别名。
将存储进程中的 SELECT 语句更改为:
Select
C.EmbossLine,
C.EmbossName,
round(CB.TotalLoading,2) as TotalLoading,
round(CB.Totalredemption,2) as TotalRedemption,
round(CB.CardBalance,2) as CardBalance
from Card C inner join CardBalance CB on CB.PAN=C.EmbossLine
当您对列执行操作时(例如 round(CB.TotalLoading,2)
)它不再有名字。您可以使用 AS
给它起一个名字,比如
SELECT C.EmbossLine, C.EmbossName, ROUND(CB.TotalLoading, 2) AS 'RoundedTotalLoading',...