Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Sir,
how to store the phone number into the database?
sir, I have taken phone number field of datatype bigint in sql and int in asp.net than when I am giving value from frontend it is giving exception .i.e; "Error in converting bigint to int".

Thank you...
Posted
Updated 20-Apr-11 20:04pm
v2
Comments
Shristi Tyagi 21-Apr-11 2:10am    
Sir, please tell me how to store a 10 digit phone number into database?
please give any example.
RaviRanjanKr 21-Apr-11 2:28am    
Use varchar because standard phone no format start with country codes which are usually specified with +, for instance +12...
as +91 etc. :)
Shristi Tyagi 21-Apr-11 2:37am    
sir i have taken but the error is remain same.
RaviRanjanKr 21-Apr-11 3:09am    
see my solution :)

The bigint data type follows the same rules and principles as the int data type except that its field can hold numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. It is somehow equivalent to the C++' long integer but more accurately equivalent to the .NET Framework's System.Int64 data type.
you can also apply this data type for a column that would hold (very) large numbers. The .NET Framework database equivalent to this data type is the SqlInt64 class which resides in System.Data.SqlTypes
The .NET equivalent of SqlDbType.BigInt is Int64 (long) so You can use Convert.ToInt64 and long type.
 
Share this answer
 
Comments
Shristi Tyagi 21-Apr-11 2:26am    
comm.Parameters.AddWithValue("@phonenumber",Convert.ToInt64(TextBox4.Text));

sir i am doing as i have shown above but it is giving the error..i.e; "Error in converting bigint to int".
please tell me only that what should i do by which my code can work.
RaviRanjanKr 21-Apr-11 3:00am    
Check my another solution.
In addition to my previous solution this solution based on Shristi Comments

Hey, Shristi I've created a table
create table address(name varchar(25),pno bigint)

you can see I've used pno[PhoneNo] as bigint datatype
and saved data by using below code it works better and saving data successfully
SqlConnection con = new SqlConnection("Database Connection String");
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into address values(@name,@pno)", con);
            cmd.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,25));
            cmd.Parameters["@name"].Value = textBox1.Text;
            cmd.Parameters.Add(new SqlParameter("@pno",SqlDbType.BigInt));
            cmd.Parameters["@pno"].Value = Convert.ToInt64(textBox2.Text);
            cmd.ExecuteNonQuery();            
 
Share this answer
 
Comments
Vishal Chandigarh 23-May-12 3:58am    
Sir how to create a project which run on local pc as well as in IIS and we have to take care that it store its backup file on another drive so that if the software cruppted we are not affected
Hope this[^] might help you.
 
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