How to insert a phone number into a table using asp.net?
string insertquery =
"insert customer (
id, name, address, gender, DOB, contactno, email, userid, password)
values
(@custid, @custname, @custaddress, @gender, @custdob,
@custcno, @custemail, @custuserid, @custpassword)";
Here custcno is the phone number.
sc.Parameters.AddWithValue("@custcno",Convert.ToInt32(txtcustcno.Text));
While running I’m getting error Input string was not in a correct format.
in table contactno is varchar(50)
The code is trying to convert the telephone number string to a number here:
So, if it contains any non-numeric characters like dashes of parentheses then it’ll throw an exception.
To just insert the string without first converting it, do this: