我从表中读取数据时遇到问题。这是我的编码示例
Dim SqlQry As String = "SELECT Distinct(RechargeAmt) from KioskItem where TelcoID='" & TelcoID & "'"
Dim SqlCmd As New SqlCommand(SqlQry, Conn)
Dim dr As SqlDataReader = SqlCmd.ExecuteReader
dr.Read()
If dr.HasRows Then
While dr.Read()
Dim SqlQry As String = "SELECT Distinct(RechargeAmt) from KioskItem where TelcoID='" & TelcoID & "'"
Dim SqlCmd As New SqlCommand(SqlQry, Conn)
Dim dr As SqlDataReader = SqlCmd.ExecuteReader
dr.Read()
If dr.HasRows Then
While dr.Read()
RechargeAmt = dr(0)
a = a & RechargeAmt & ";"
End While
End If
If a = 0 Then
Return RechargeAmt
Else
Return a
End If
我的问题是如果数据超过一行,将数据保存到字符串中没有问题,但是当我表中的数据只有一行时,它无法读取数据。我试试这个
If dr.HasRows Then
RechargeAmt = dr(0)
While dr.Read()
a = a & RechargeAmt & ";"
End While
End If
If a = 0 Then
Return RechargeAmt
Else
Return a
End If
但它仍然无法从表中读取数据