LuckyLuke82 LuckyLuke82 - 3 months ago 21
Vb.net Question

concatenate Combobox items from Oracle DB

I want to display 2 table values from Oracle DB in combobox (name and surname). So far I can display only one, and this one also doesn't work with WHERE criteria.

Using conn As OracleConnection = New OracleConnection("Data Source=MyDB;User Id=Lucky;Password=MyPassword;")

Try

conn.Open()

Dim SQL As String
NIZ = "SELECT Name,Surname from MyTable where ID=1 "
Dim Cmd As New OracleCommand(SQL, conn)
Cmd.CommandType = CommandType.Text

Dim dr As OracleDataReader = Cmd.ExecuteReader()

While (dr.Read())
CmbCustomers.Items.Add(dr.GetString(0))
End While

conn.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Dispose()
End Try


Anybody knows how I could display name and surname together in combobox, with WHERE clause ?

Answer

Try using string concatenation this way

 SELECT Name ||' ' || Surname from MyTable where ID=1

if you need alignment you can try padding

 SELECT Name || RPAD(' ', (12 - length(Name),' ') ||  '-  ' || Surname from MyTable where ID=1