【问题标题】:Refresh TextBox刷新文本框
【发布时间】:2013-07-08 14:52:39
【问题描述】:

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

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

【问题讨论】:

    标签: mysql vb.net textbox refresh


    【解决方案1】:

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

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

    【讨论】:

    • 它不起作用,当我在数据库中输入新数据时,数据不会显示在文本框中,但是当我再次运行时,数据会显示
    【解决方案2】:
            While DR.Read
                txtData.Text &= DR.Item("CostumerOrder") & Space(10) & DR.Item("OrderPrice") & vbCrLf
                txtData.Update()
            End While
    

    【讨论】:

    • 它不起作用,当我在数据库中输入新数据时,数据不会显示在文本框中,但是当我再次运行时,数据会显示。
    • 但是文本框没有绑定到数据库。除非您这样做,否则它不会显示 数据。
    猜你喜欢
    • 1970-01-01
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多