Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello,
I have two text-boxes, one for firstname and other for lastname. When I store it into database, it looks like firstnamelastname but I need space in between them like (firstname lastname). So how it can be possible and what I have to do ?

Thanks,
Posted
Comments
Ramug10 10-Jun-14 6:04am    
did you tried any code??

hey priyanka...

simply store the values of both textboxes in a string variable and pass that variable to sql query.

for example,

string fullName = txtFirstName.Text + " " + txtLastName.Text;

and now pass this variable to sql query

for ex,

insert into tblName values (fullName);

gud luck
 
Share this answer
 
Don't.
If you get information in separated fields, store them in separated fields.
Otherwise, you are throwing information away, and making assumptions about the information!

Store them in separate fields, and you can retrieve the "first name" for friendly greetings:
C#
string greet = "Hi " + firstName;
Or add an honorific:
C#
string greet = "Dear Mr " + lastName;

You can retrieve the "full name" from the DB at any time:
SQL
SELECT FirstName + ' ' + LastName AS [Full Name] FROM MyTable
 
Share this answer
 
Comments
Peter Leow 10-Jun-14 6:13am    
That's the way! 5ed.
use like below

string Name = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim();


you just use variable Name and pass it into database.


Thanks,
-RG
 
Share this answer
 
During insert

SQL
insert into TableName (FullName) values (@firstName+' '+@LastName)


pass textbox values to @firstName and @LastName

During Select

SQL
select FirstName+' 'LastName as FullName from TableName
 
Share this answer
 
v2
C#
string fullName = txtFirstName.Text + " " + txtLastName.Text;


But how do you get the First Name and Last Name back as separate fields to be displayed back? Store them as separate columns in the database.
 
Share this answer
 
Comments
Priyanka Bhawsar 10-Jun-14 6:08am    
thanks to answer me. I have did that.

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