I would suggest not using SELECT * but SELECT fields you want then data bind to your text boxes.
The following example is OleDb but MySQL provider works the same. I don't have a MySQL database to provide you with an exact demo.
Load data from database
In this example I have a BindingNavigator which allow the user to traverse all rows in the underlying DataTable of the BindingSource bsCustomers. Then bind a column in the DataTable named CompanyName to TextBox txtCompanyName.Code:Private Function Load_Customers() As DataTable Using cn As New OleDb.OleDbConnection With {.ConnectionString = "Your connection string"} Using cmd As New OleDb.OleDbCommand With {.Connection = cn} cmd.CommandText = "SELECT CompanyName, ContactName, ContactTitle, Identifier FROM Customer" Dim dt As New DataTable cn.Open() dt.Load(cmd.ExecuteReader) Return dt End Using End Using End Function
Code:Public Class frmMainForm WithEvents bsCustomers As New BindingSource Private Sub frmMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load bsCustomers.DataSource = Load_Customers() BindingNavigator1.BindingSource = bsCustomers txtCompanyName.DataBindings.Add("Text", bsCustomers, "CompanyName") End Sub End Class




Reply With Quote
