如何刷新我的文本框時,在數據庫 輸入數據這裏是我的代碼....刷新文本框
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
它不起作用,當我在數據庫上輸入新數據時數據不顯示在文本框上,但是當我再次運行它時,數據顯示 –