Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi sir/mam,
i have a field
PhoneNumber,
this field has three textboxes,one for national code,other for region code and last one for phonenumber.
now,how would i store these textboxes value in database.
When we have single textbox then we add through

SqlCommand comm.Parameters.AddWithValue("@emailadd", TextBox1.Text);


Since,i have three textboxes,my problem is that how to store these textboxes value in database?

Thanku,
Posted
Updated 11-Apr-11 19:43pm
v2
Comments
Wild-Programmer 12-Apr-11 1:50am    
Ma'am! That reminds me, I have never seen female member in Code project :D
SURBHI TYAGI 12-Apr-11 1:55am    
excuse me sir,may i know why so?
Eduard Keilholz 12-Apr-11 1:57am    
Yes, I'm curious who is going to answer this question? ;)
SURBHI TYAGI 12-Apr-11 2:12am    
Amit sir,is there not any female memeber?
Wild-Programmer 12-Apr-11 22:59pm    
Never saw any on Code project. I think that makes you the first one :)

Hey!

Have you tried to add the fields together with the '+' operator?
C#
SqlCommand comm.Parameters.AddWithValue("@emailadd", TextBox1.Text + TextBox2.Text + TextBox3.Text);


The code above will work! However, there's a neater way. If you want to modify strings, Microsoft recommends using the StringBuilder which will handle string operations way faster. Consider the code below for example :
C#
StringBuilder phoneNumber = new StringBuilder();
phoneNumber.Append("(");
phoneNumber.Append(textBox1.Text);
phoneNumber.Append(") ");
phoneNumber.Append(textBox2.Text);
phoneNumber.Append(" ");
phoneNumber.Append(textBox3.Text);

SqlCommand comm.Parameters.AddWithValue("@emailadd", phoneNumber.ToString());


And then a final quick note : Please notice you're using the @emailadd parameter to insert a phone number, this may be a typo?

Good luck!

Eduard
 
Share this answer
 
Comments
SURBHI TYAGI 12-Apr-11 1:53am    
ohh sorry sir for @emailadd,here i have just give example.
And Thanks alot sir,its working.
Eduard Keilholz 12-Apr-11 1:59am    
If it's working, then please accept the answer so others don't spend time on answering your question, while the problem is already solved!
SURBHI TYAGI 12-Apr-11 2:13am    
ya sir i have done.
Eduard Keilholz 12-Apr-11 2:29am    
No you have not. Hit the green 'Accept solution' button..
I could not understand what is the actual problem you are facing.
If you have three textboxes and want to store the data in a single column only, then first get the value of all the three textboxes in a local variable and format it according your own requirement and pass it as a parameter to SQL
 
Share this answer
 
v2
try this

string PhoneNumber= TextBox1.Text +" "+ TextBox2.Text +" "+ TextBox3.Text;

  SqlCommand comm.Parameters.AddWithValue("@PhoneNumber",PhoneNumber);
 
Share this answer
 
Comments
Eduard Keilholz 12-Apr-11 2:31am    
It's quicker to use a StringBuilder if you add up strings like this.
[]
 
Share this answer
 
Comments
m@dhu 12-Apr-11 6:35am    
I couldn't see any link. update it.
i want to save data from multiple text boxes to one field in msaccess and once one of that textbox is filled then again it can't be filled...so can anyone give me solution for this above in vb6 and msaccess....
 
Share this answer
 
v2
so can anyone give me solution for this above in vb6 and msaccess....
 
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