我有一个表,它总是只有3行,每周更新。我需要阅读他们和填充3个imageurl的和3个相关的超链接。但是,我得到了一个错误:
System.IndexOutOfRangeException: hyperlink1
我可能离这里太远了,因为我还在学习,但我们走了。。我只是用。。
SELECT
(SELECT hyperlink As hyperlink1 WHERE productNo=1),
(SELECT imageUrl As imageUrl1 WHERE productNo=1),
(SELECT hyperlink As hyperlink2 WHERE productNo=2),
(SELECT imageUrl As imageUrl2 WHERE productNo=2),
(SELECT hyperlink As hyperlink3 WHERE productNo=3),
(SELECT imageUrl As imageUrl3 WHERE productNo=3)
从TBL产品端
然后vb代码。。
Public Function GetAmazonProducts()
Dim DBConnectAm As New DBConn
Using db As DbConnection = DBConnectAm.Conn("DBConnectionString")
Dim cmd As SqlCommand = DBConnectAm.Command(db, "SelectAmazonProducts")
'cmd.Parameters.Add(New SqlParameter("productNo", SqlDbType.Int, ParameterDirection.Input)).Value = productNo
db.Open()
Dim DR As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
hypAmazonProduct1.navigateurl=DR("hyperlink1")
imghypAmazonProduct1.ImageUrl=DR("imageUrl1")
hypAmazonProduct2.navigateurl=DR("hyperlink2")
imghypAmazonProduct2.ImageUrl=DR("imageUrl2")
hypAmazonProduct3.navigateurl=DR("hyperlink3")
imghypAmazonProduct3.ImageUrl=DR("imageUrl3")
DR.Close()
DR = Nothing
cmd.Dispose()
cmd = Nothing
db.Dispose()
db.Close()
End Using
End Function
1条答案
按热度按时间8xiog9wr1#
我将do while放回原处,然后在每行中抖动select语句,使其看起来像这样:
vb。。