Click here to Skip to main content
15,898,599 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to show two columns data from sql server table to one textbox in c#

i use the sql command:
SqlCommand cmd = new SqlCommand("Select distinct Branch,Emp_id,UPPER(First_name+' '+Last_name) from Userinfo where User_name = '" + Session["userName"].ToString() + "'", con);

But what i write in ::

C#
while (dr.Read())
                {
                    tbbranch.Text = dr["Branch"].ToString();
                    tbempid.Text = dr["Emp_id"].ToString();
                    tbempname.Text = ?????????

                }
Posted

SQL
SqlCommand cmd = new SqlCommand("Select distinct Branch,Emp_id,UPPER(First_name+' '+Last_name) as FullName from Userinfo where User_name = '" + Session["userName"].ToString() + "'", con);



and then

C#
while (dr.Read())
                {
                    tbbranch.Text = dr["Branch"].ToString();
                    tbempid.Text = dr["Emp_id"].ToString();
                    tbempname.Text = dr["FullName"].ToString();

                }
 
Share this answer
 
Comments
Maciej Los 17-Apr-13 7:59am    
+5
Rockstar_ 17-Apr-13 8:14am    
yes
See solution 1. Another way is:
C#
while (dr.Read())
                {
                    tbbranch.Text = dr["Branch"].ToString();
                    tbempid.Text = dr["Emp_id"].ToString();
                    tbempname.Text = dr["FirstName"].ToString() + " " + dr["LastName"].ToString();
                 }

but FirstName and LastName must be in SELECT list.
 
Share this answer
 
HI pal,
This is one way try it
concatenate and trim the data into where you want keep it .........

SQL
SqlCommand cmd = new SqlCommand("Select distinct Branch,Emp_id,UPPER(First_name+' '+Last_name) from Userinfo where User_name = '" + Session["userName"].ToString() + "'", con);


C#
while (dr.Read())
                {
                    tbbranch.Text = dr["Branch"].ToString().Trim();
                    tbempid.Text = dr["Emp_id"].ToString().Trim();
                    tbempname.Text = tbbranch.Text +" "+ tbempid.Text ;
                }.
 
Share this answer
 
Try this:

C#
tbbranch.Text = dr["Branch"].ToString();
tbempid.Text = dr["Emp_id"].ToString();
tbempname.Text = dr["Branch"].ToString() + "  " +dr["Emp_id"].ToString();
 
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