0
我从表中读取数据时遇到问题。这是我的编码无法读取多于一行的数据
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
我的问题是:如果数据有多个行,它没有任何问题的数据保存到一个字符串,但是当我的表中的数据只有一个rowm,它是在样品无法读取数据。我尝试这个
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
,但它仍然无法从表