我收到错误' Single'来自SingleRoom = dr("Single").ToString
行。我没有长时间编程。我希望能够在数据库中搜索最近的日期(上次修改时间),然后使用同一行中其他字段的数据显示为标签。
Dim PriceFound As String = False
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
MyConn.Open()
str1 = ("SELECT `Last Modified` FROM [Prices] ORDER BY `Last Modified` DESC")
Dim cmd1 As OleDbCommand = New OleDbCommand(str1, MyConn)
dr = cmd1.ExecuteReader
While dr.Read()
PriceFound = True
DateDisplay = dr("Last Modified").ToString
SingleRoom = dr("Single").ToString
DoubleRoom = dr("Double").ToString
FamilyRoom = dr("Family").ToString
AdultPrice = dr("Adult").ToString
ChildPrice = dr("Child").ToString
If PriceFound = True Then
LblPriceAdult.Text = AdultPrice
LblPriceChild.Text = ChildPrice
LblPriceDoubleRoom.Text = DoubleRoom
LblPriceFamilyRoom.Text = FamilyRoom
LblPriceSingleRoom.Text = SingleRoom
End If
End While
MyConn.Close()
答案 0 :(得分:0)
您的查询应该是:
"SELECT * FROM [Prices] ORDER BY `Last Modified` DESC"
...以便它将检索SELECT子句中的其他列/字段。当前查询仅检索Last Modified
列。
=====
此外,如果您只想选择特定列,可以在查询中执行此操作:
请注意,列顺序 NOT 很重要 - 我只是在此示例中匹配您的列表。
"SELECT `Last Modified`, Single, Double, Family, Adult, Child FROM [Prices] ORDER BY `Last Modified` DESC"