Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using (SqlCommand sqlCmd = new SqlCommand())
                 {
                     sqlCmd.CommandText = "SELECT LNAME FROM PAYMAST";
                     sqlCmd.Connection = sqlConn;
                     sqlConn.Open();
                     SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
                     DataTable dt = new DataTable();
                     da.Fill(dt);
                     DropDownList1.DataSource = dt;
                     DropDownList1.DataValueField = "LNAME";
                     DropDownList1.DataTextField = "LNAME";
                     DropDownList1.DataBind();
                     sqlConn.Close();



Need to replace the field name 'LNAME' with a combination of 2 fields ie

'FNAME' +' '+'LNAME'.

How do you accomplish it in the settings above?

Thanks

What I have tried:

Reviewed my own codes and others and the net , but found none close to this scenario
Posted
Updated 10-Oct-17 22:03pm

1 solution

Try:
C#
sqlCmd.CommandText = "SELECT LNAME + ' ' + FNAME AS [Name] FROM PAYMAST";
...
DropDownList1.DataValueField = "Name";
DropDownList1.DataTextField = "Name";
 
Share this answer
 
Comments
Member 12770648 11-Oct-17 5:49am    
How do you trim LNAME + ' ' + FNAME
OriginalGriff 11-Oct-17 6:58am    
Please don't assume that we will understand what you mean if you type the minimum text possible: Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So try asking that again, giving us the context to understand what your problem is.
Richard Deeming 12-Oct-17 14:35pm    
Assuming Microsoft SQL Server:
sqlCmd.CommandText = "SELECT LTRIM(RTRIM(LNAME + ' ' + FNAME)) AS [Name] FROM PAYMAST";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900