I am running ASP.NET application written in C# and using SQL Server 2005. I am having a contact number textbox in which I have to enter integers alone. I want the database to get the integers alone but if I give characters also it is getting entered. How can I avoid characters to store in the database? How to code for this?
1 Answer
As per the information that you've provided, there are 2 things that you need to do:
Validate the user input and make sure they only enter numbers in the textbox provided to enter the phone numbers.
Make sure the column in your SQL table to store the contact number is an int and not a varchar/char.
Hope this makes sense.
2 Comments
jeni
hi your answer is very much helpful,but it isn't working out.I tried ALTER TABLE register ALTER COLUMN contact nvarchar(50) int this query to change datatype.it is showing error.
Andriy M
@jeni: You used the wrong syntax. Here's how:
ALTER TABLE register ALTER COLUMN contact int. But it will fail if the column still contains any non-numeric values, so first make sure you've cleaned up your data.