How to concatenate multiple coloumns from database and display it in a textbox

I have one textbox of primary name in my form and i want to fetch its value from database from three fields first_name , middle_name and last name present in my database...

I did the following coding but its not giving the required answer...Kindly help me in finding out the error
Sukesh ShuklaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Easwaran ParamasivamCommented:
Your code should work fine. You got the FullName from database combining the 3 names separated by space. It should display in text box correctly. Assuming all the 3 names containing some value. If any one of them is null it won't work. You should use either isnull or coalesce function to omit them. Please google for that.

Let me know if you have any other problem.
Sukesh ShuklaAuthor Commented:
I used Coalese function but it is giving error as:-

Conversion failed when converting the nvarchar value 'Pratibha                       ' to data type int.
Easwaran ParamasivamCommented:
Instead of 0 use ''. Again if middle name is null you will get two spaces. Using replace function replace the two spaces with single space.

I hope I made it clear.
Sukesh ShuklaAuthor Commented:
where and how to use this replace function
Easwaran ParamasivamCommented:
 String str = SELECT REPLACE(First_Name + ' ' + COALESCE(Middle_Name,'') + ' ' + Last_Name, '  ', ' ')  AS Full_Name FROM Primary_Member where Flat='" + TextBoxFN.Text.Trim() + "'";

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.