Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,


what data type can i use to store phone numbers in c# and sql server 2005?


please anybody help me.

Thanks in advance
Posted

From What datatype should be used for storing phone numbers in SQL Server 2005?[^]:
Quote:
Does this include:

International numbers?
Extensions?
Other information besides the actual number (like "ask for bobby")?

If all of these are no, I would use a 10 char field and strip out all non-numeric data. If the first is a yes and the other two are no, I'd use two varchar(50) fields, one for the original input and one with all non-numeric data striped and used for indexing. If 2 or 3 are yes, I think I'd do two fields and some kind of crazy parser to determine what is extension or other data and deal with it appropriately. Of course you could avoid the 2nd column by doing something with the index where it strips out the extra characters when creating the index, but I'd just make a second column and probably do the stripping of characters with a trigger.

Update: to address the AJAX issue, it may not be as bad as you think. If this is realistically the main way anything is done to the table, store only the digits in a secondary column as I said, and then make the index for that column the clustered one.
 
Share this answer
 
Dear friend
it is common sense that the non calculative numeric field should be string :)
 
Share this answer
 
In SQL you need to create the column as varchar datatype

To access that value in C# take string variable
 
Share this answer
 
v2
Comments
Amir Mahfoozi 9-Nov-11 5:03am    
+5 for simple and effective answer
sravani.v 9-Nov-11 5:11am    
Thank you Amir
The phone number are in different way like
some one start from + ,it may me - symbol
like
+91-9999999999
so according to me you should take varchar, becoz phon no is fixed and no need to calculate so no requirement to take it as integer.
 
Share this answer
 
Comments
Lin Jiamei 1-Feb-14 17:16pm    
And it does not add an extra space in your database if (e.g) nvarchar10 did not reach 10 digits.
I always use varchar(50) . Its a best way to store phone no.
 
Share this answer
 
Use the VarChar Datatype it is useful For you :).
 
Share this answer
 
You can use Bigint [^]in sql server and BigInteger[^] in C#.

hope it helps :)
 
Share this answer
 
Comments
udaysimha 9-Nov-11 2:59am    
hi P.singh

Thanks for u r reply, i have a doubt that there is no BigInteger datatype in c#,
if we want how to get that datatype or is there any alternative is avilable for BigInteger in c#.


please let me know.
Uday P.Singh 9-Nov-11 4:49am    
did you visited the link I provided? If you had then you would have not downvoted my answer. BigInteger is a datatype introduce in .net framwork 4.
udaysimha 9-Nov-11 5:17am    
Hi P.Singh

Thanks a lot for your reply.
rajrprk 9-Nov-11 4:55am    
Better U can set as a varchar (or) nvarchar field
To save Mobile No in sqlsever 2005 u can use int or varchar but it depends if u would like to show in girdview u can use both but in case of int u have to condition because if u edit records of mobile phone on having int its datatype it will store 0 if u want Null then u have to use 'cases' in showgrid procedure like this below
(Case MobileNo when 0 then Null else MobileNo end)MobileNo

In cas of using varchar u won't suffer from these problems
 
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