0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

should use Ampersand for string concat: a = b & c & d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.