• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Returning a concatenated value from a data table using a select SQL satement

I am wondering why this code in VB.NET doesnt work and it works fine in access. I want to return user surname and other names as one string usernames

SELECT StrConv([surname],3) & " " & StrConv([othernames],3) AS usernames, users.userId,
FROM users;

Anthony
0
Anthony Matovu
Asked:
Anthony Matovu
  • 2
1 Solution
 
CodeCruiserCommented:
Use + instead of &

SELECT StrConv([surname],3) + " " + StrConv([othernames],3) AS usernames, users.userId,
FROM users;
0
 
Anthony MatovuBusiness Analyst, MTN UgandaAuthor Commented:
Thank you
i get the error msg

Syntax error (missing operator) in query expression 'StrConv([surname],3) StrConv([othernames],3)'.

this is the code

 dadp = New OleDb.OleDbDataAdapter("SELECT StrConv([surname],3)" + " " + "StrConv([othernames],3) AS usernames, users.userId, FROM users;", db)
        dT = New DataTable : dadp.Fill(dT) : dadp.Dispose()
        CType(frm.Controls("compBy"), ComboBox).DataSource = dT
        CType(frm.Controls("compBy"), ComboBox).DisplayMember = "usname" : CType(frm.Controls("compBy"), ComboBox).ValueMember = "userId"
        CType(frm.Controls("compBy"), ComboBox).BindingContext = New BindingContext : CType(frm.Controls("compBy"), ComboBox).SelectedIndex = -1


0
 
CodeCruiserCommented:
The plus needs to be within the quotes

 dadp = New OleDb.OleDbDataAdapter("SELECT StrConv([surname],3)" + " " + "StrConv([othernames],3)

to

 dadp = New OleDb.OleDbDataAdapter("SELECT StrConv([surname],3) + ' ' + StrConv([othernames],3) AS usernames, users.userId, FROM users;", db)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now