刷新TextBox

时间:2013-07-10 15:23:54

标签: mysql vb.net textbox refresh

在数据库中输入数据时,如何刷新文本框 这是我的代码......

Imports MySql.Data
Imports MySql.Data.MySqlClient

Public Class Form1
    Dim dbCon As MySqlConnection
    Dim strQuery As String = ""
    Dim SQLCmd As MySqlCommand
    Dim DR As MySqlDataReader

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GetDBData()
    End Sub

    Private Sub GetDBData()
        Try
            dbCon = New MySqlConnection("Server=localhost; Database=mydatabase;Uid=root;Pwd=;")
            strQuery = "SELECT *" & _
                    "FROM tbl_user"

            SQLCmd = New MySqlCommand(strQuery, dbCon)
            dbCon.Open()
            DR = SQLCmd.ExecuteReader

            While DR.Read
                txtData.Text = txtData.Text & DR.Item("CostumerOrder") & Space(10) & DR.Item("OrderPrice") & vbCrLf
            End While

        Catch ex As Exception
            MsgBox("FAIL CONNECT!" & vbCrLf & vbCrLf & ex.Message)
        End Try
    End Sub

    Private Sub txtData_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtData.TextChanged

    End Sub
End Class

2 个答案:

答案 0 :(得分:0)

这是一个丑陋的解决方案,但你可以试试这个......

While DR.Read
    txtData.Text = txtData.Text & DR.Item("CostumerOrder") & Space(10) & DR.Item("OrderPrice") & vbCrLf
    Application.DoEvents()
End While

答案 1 :(得分:0)

        While DR.Read
            txtData.Text &= DR.Item("CostumerOrder") & Space(10) & DR.Item("OrderPrice") & vbCrLf
            txtData.Update()
        End While