R
rn5a
A SQL Server 2005 stored procedure expects a parameter 'UserID'
depending upon which it retrieves the no. of records & OrderIDs
corresponding to the 'UserID' from a DB table (note that OrderID &
UserID are two of the columns in the DB table). So for e.g. consider a
user whose UserID=6 & the DB table has 3 records whose UserID=6. In
other words, there are 3 OrderID records of the user whose UserID=6,
say, OrderID=8, OrderID=17 & OrderID=29. The stored procedure will
finally return 2 columns - the OrderCount (which is 3 for UserID=6) &
the OrderID (which will be 8, 17 & 29 for UserID=6). This is the stored
procedure:
ALTER PROCEDURE dbo.NETAllOrders
@UserID int
AS
DECLARE
@OrderCount int
SET @OrderCount = (SELECT COUNT(OrderID) FROM NETOrders WHERE UserID =
@UserID)
SELECT @OrderCount AS OrderCount, OrderID
FROM
NETOrders
WHERE
UserID = @UserID
In a VB class file, I am invoking the stored procedure in a function
named 'GetOrderCount' which returns a SqlDataReader back to the calling
ASPX page. I want the ASPX page to display the 3 OrderIDs of UserID=6
in a Label control. Unlike the DataBinding controls like DataList,
DataGrid, Repeater controls, the Label control will not automatically
loop through the resultset.
So I tried to accomplish this using a For...Next loop
Dim i As Integer
Dim sqlReader As SqlDataReader
iUserID = Request.Cookies("UserID").Value
'ShopCart is the name of the class in the VB class file
boShopCart = New ShopCart
sqlReader = boShopCart.GetOrderCount(iUserID)
While (sqlReader.Read)
If (sqlReader.GetValue(0) > 1) Then
pnlLinks.Visible = True
For i = 1 To sqlReader.GetValue(0)
lblLinks.Text = sqlReader.GetValue(1)(i)
Next i
Else
pnlLinks.Visible = False
End If
End While
But this generates the following error:
No default member found for type 'Integer'.
pointing to the line
lblLinks.Text = sqlReader.GetValue(1)(i)
Can someone please correct me & suggest how do I loop through the
resultset so that I can display the records in a Label control?
depending upon which it retrieves the no. of records & OrderIDs
corresponding to the 'UserID' from a DB table (note that OrderID &
UserID are two of the columns in the DB table). So for e.g. consider a
user whose UserID=6 & the DB table has 3 records whose UserID=6. In
other words, there are 3 OrderID records of the user whose UserID=6,
say, OrderID=8, OrderID=17 & OrderID=29. The stored procedure will
finally return 2 columns - the OrderCount (which is 3 for UserID=6) &
the OrderID (which will be 8, 17 & 29 for UserID=6). This is the stored
procedure:
ALTER PROCEDURE dbo.NETAllOrders
@UserID int
AS
DECLARE
@OrderCount int
SET @OrderCount = (SELECT COUNT(OrderID) FROM NETOrders WHERE UserID =
@UserID)
SELECT @OrderCount AS OrderCount, OrderID
FROM
NETOrders
WHERE
UserID = @UserID
In a VB class file, I am invoking the stored procedure in a function
named 'GetOrderCount' which returns a SqlDataReader back to the calling
ASPX page. I want the ASPX page to display the 3 OrderIDs of UserID=6
in a Label control. Unlike the DataBinding controls like DataList,
DataGrid, Repeater controls, the Label control will not automatically
loop through the resultset.
So I tried to accomplish this using a For...Next loop
Dim i As Integer
Dim sqlReader As SqlDataReader
iUserID = Request.Cookies("UserID").Value
'ShopCart is the name of the class in the VB class file
boShopCart = New ShopCart
sqlReader = boShopCart.GetOrderCount(iUserID)
While (sqlReader.Read)
If (sqlReader.GetValue(0) > 1) Then
pnlLinks.Visible = True
For i = 1 To sqlReader.GetValue(0)
lblLinks.Text = sqlReader.GetValue(1)(i)
Next i
Else
pnlLinks.Visible = False
End If
End While
But this generates the following error:
No default member found for type 'Integer'.
pointing to the line
lblLinks.Text = sqlReader.GetValue(1)(i)
Can someone please correct me & suggest how do I loop through the
resultset so that I can display the records in a Label control?