如何将mysql结果显示为标签或文本?

时间:2014-03-12 06:55:01

标签: mysql vb.net

需要将mysql字符串的结果显示到标签或文本框。

只有一个代码将结果嵌入到listview中:

Sub fillListview()
    Try
        ListView1.Items.Clear()
        strSQL = "SELECT * FROM customer"
        objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL, objConn)
        objDR = objCmd.ExecuteReader

        While (objDR.Read())
            With ListView1.Items.Add(objDR("Cust_Id"))
                .subitems.add(objDR("Cust_Name"))
                .subitems.add(objDR("Cust_Age"))
                .subitems.add(objDR("Items"))
                .subitems.add(objDR("Price_Accumulated"))
                .subitems.add(objDR("Date"))
                .subitems.add(objDR("Time"))
            End With
        End While

        objCmd.Dispose()
        objDR.Close()

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

此外,我已经将strsql,objCmd等作为变量放入模块中,因此不需要将它作为DIM

(顺便说一句,我不知道为什么只有While被识别为代码:|)

1 个答案:

答案 0 :(得分:0)

尝试以下格式:

 Sub fillListview()
Try
    ListView1.Items.Clear()
    strSQL = "SELECT * FROM customer"
    objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL, objConn)
    objDR = objCmd.ExecuteReader

    While (objDR.Read())
           textBox.Text=objDR("Cust_Id").toString()
    End While

    objCmd.Dispose()
    objDR.Close()

Catch ex As Exception
    MsgBox(ex.Message)
End Try

End Sub

将其放在while语句中。