Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SqlConnection connect = new SqlConnection();
               connect.ConnectionString = ConfigurationManager.ConnectionStrings["WEBHR"].ConnectionString;
               connect.Open();
               SqlDataAdapter da = new SqlDataAdapter("select * from Transfer order by empno", connect);

               DataSet ds = new DataSet();
               da.Fill(ds, "Transfer");

               txt_Empno.Text             = ds.Tables["Transfer"].Rows[0]["EMPNO"].ToString();
               txt_Name.Text              = ds.Tables["Transfer"].Rows[0]["FNAME"].ToString();




The request is
txt_Name.Text 
is 'FNAME'+' '+'LNAME'

How do you combine 2 fields

Please assist

What I have tried:

The above is the issue no example from my search
Posted
Updated 29-Apr-19 22:00pm

For starter, don't use SELECT * FROM ... - it's a much better idea to list the columns you wish to return as it future proofs your app as well as not wasting bandwidth on data you aren't going to use.

And if you do, you can combine fields in SQL:
SQL
SELECT EmpNo, FName + ' ' + LName AS [Name] FROM Transfer ORDER BY EmpNo
 
Share this answer
 
Comments
Member 12770648 28-Apr-19 9:00am    
Problem it picks only the first field only and the expected result is not achieved
Member 12770648 28-Apr-19 9:01am    
The combination is not achieved.
Member 12770648 28-Apr-19 9:03am    
SqlConnection connect = new SqlConnection();
connect.ConnectionString = ConfigurationManager.ConnectionStrings["WEBHR"].ConnectionString;
connect.Open();
SqlDataAdapter da = new SqlDataAdapter(@"Select TRANS_NO,IDNO,EMPNO,LNAME+' '+FNAME AS [NAME],
CURR_BRANAME,CURR_BRANCH,CURR_DEPT,CURR_DEPTNAME,CURR_SECTNAME,
CURR_SECTN,TRANS_TYPE,DEPT,DEPTNAME,BRANAME,BRANCH,SECTNAME,SECTN,
SUP_NAME,SUP_NO,TRANDATE,EFF_DATE,GRANT1
from Transfer order by empno", connect);


DataSet ds = new DataSet();
da.Fill(ds, "Transfer");

txt_Trans.Text = ds.Tables["Transfer"].Rows[0]["TRANS_NO"].ToString();
txt_Code.Text = ds.Tables["Transfer"].Rows[0]["IDNO"].ToString();
txt_Empno.Text = ds.Tables["Transfer"].Rows[0]["EMPNO"].ToString();
txt_Name.Text = ds.Tables["Transfer"].Rows[0]["NAME"].ToString();
Member 12770648 28-Apr-19 9:20am    
How do you TRIM the fields
OriginalGriff 28-Apr-19 10:20am    
How do you trim which fields?
Alternatively to solution #1 by OriginalGriff[^], here is another way:
C#
DataRow dr = ds.Tables["Transfer"].Rows[0];
txt_Name.Text = string.Concat(dr["FNAME"].ToString().Trim(), " ", dr["LNAME"].ToString().Trim());
 
Share this answer
 

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