# Load SQL Data into TextBox/Label VB.NET



## deadscenekid (Apr 26, 2006)

My question is, I was wondering whether there was a way to load MySQL Data into a TextBox/Label in VB.NET.
This is the code I have been using thus far to load MySQL Data into a DataGridView:

```
Public Function RefreshData()
        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim myData As New DataTable
        Dim SQL As String

        SQL = "SELECT p.project_id AS ID, p.project_code AS ProjectCode, p.project_name AS ProjectName, p.client AS Client, p.project_leader AS ProjectLeader, p.project_release AS ProjectRelease, p.description AS Description, DATE_FORMAT(p.start_date,%b %d %Y - %r) AS StartDate, DATE_FORMAT(p.end_date,%b %d %Y - %r) AS EndDate  FROM projects p"

        conn.ConnectionString = MY_CONNECT

        Try
            conn.Open()

            Try
                myCommand.Connection = conn
                myCommand.CommandText = SQL

                myAdapter.SelectCommand = myCommand
                myAdapter.Fill(myData)

                dgvCurrent.DataSource = myData
                dgvCurrent.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
            Catch myerror As MySqlException
                MsgBox("There was an error reading from the database: " & myerror.Message)
            End Try
        Catch myerror As MySqlException
            MessageBox.Show("Error connecting to the database: " & myerror.Message)
        Finally
            If conn.State <> ConnectionState.Closed Then conn.Close()
        End Try
    End Function
```


----------

