user3678904
user3678904

Reputation: 33

Displaying the values of 3 different columns on a single string with MySQL using VB.Net

Good day. I want to know how to display the values of three different columns on a single string. The three columns are lastname, middlename, and firstname. I want them to Display on the order of firstname, middlename and lastname on a single line. What I did was kind of noobish because I just placed them on two different text labels because I don't know how to put them on a single string. Can anyone help me? Here's my code:

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles  Button2.Click
    Dim connString As String = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
    Dim sqlQuery As String = "SELECT emp_lastnm, emp_firstnm FROM employee_table WHERE emp_no = @empno"

    Using sqlConn As New MySqlConnection(connString)
        Using sqlComm As New MySqlCommand()
            With sqlComm
                .Connection = sqlConn
                .CommandText = sqlQuery
                .CommandType = CommandType.Text
                .Parameters.AddWithValue("@empno", txtEmpno.Text)
            End With
            Try
                sqlConn.Open()
                Dim sqlReader As MySqlDataReader = sqlComm.ExecuteReader()
                While sqlReader.Read()
                    Label4.Text = sqlReader("emp_lastnm").ToString()
                    Label5.Text = sqlReader("emp_firstnm").ToString()
                End While
            Catch ex As MySqlException

            End Try
        End Using
    End Using

End Sub

Upvotes: 0

Views: 58

Answers (1)

Horaciux
Horaciux

Reputation: 6477

You need jut to concatenate both texts:

Label4.Text = sqlReader("emp_firstnm").ToString() & " " & sqlReader("emp_lastnm").ToString() 

You are not retrieving middle name from DB. When you do, just put it in the middle and add some blank spaces as indicated above

Upvotes: 1

Related Questions