大家好,我想自动检测价格并在Visual Basic 2008中从数据库显示在文本框中,这是我的代码,但无法正常工作。任何建议,谢谢
表名称:transporter_profile 列名称:价格
Private Sub load_transportation()
Dim sqlquery As String
Dim myCommand As New MySqlCommand
Dim myData As MySqlDataReader
tb_test.Clear()
sqlquery = "SELECT price FROM transporter_profile ORDER BY
price"
ConnectmyDB()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myData = myCommand.ExecuteReader
If myData.HasRows = False Then
Else
While myData.Read()
tb_test.Text = myData.GetString("price")
End While
End If
DisconnectDatabase()
End Sub
答案 0 :(得分:1)
尝试使用此源代码:
Private Sub load_transportation()
Dim sqlquery As String
Dim myCommand As New MySqlCommand
Dim myData As MySqlDataReader
tb_test.Items.Clear()
sqlquery = "SELECT price FROM transporter_profile ORDER BY price"
ConnectmyDB()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myData = myCommand.ExecuteReader
If myData.HasRows = False Then
Else
While myData.Read()
tb_test.Items.Add(myData.GetDouble("price"))
End While
End If
DisconnectDatabase()
End Sub