Ive made a registration form(using asp.net and C#) with some attributes like username, password,date of birth,phone no,address, gender, postal code etc. There's no error in the code.
But When I run my web site and fill in the details, and press the OK button, I get an error:"Input string was not in a correct format."
Plz help me!
the code is:
private void ExecuteInsert(string Username, string Password, string Confirmpassword, string EmailID, string Firstname, string Lastname, string Address, string City,string State, string Country, string Postalcode,string PhoneNo, string gender, string DOB)
{
SqlConnection con = new SqlConnection(" Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Online job portal\\App_Data\\database.mdf;Integrated Security=True;User Instance=True");
string sql = "INSERT INTO ojb1(Username,Password,ConfirmPassword,EmailID,Firstname,Lastname,Address,City,State,Country,Postalcode,PhoneNo,Gender,DOB) VALUES" + "(@Username,@Password,@ConfirmPassword,@EmailID,@Firstname,@Lastname,@Address,@City,@State,@Country,@Postalcode,@PhoneNo,@Gender,@DOB)";
try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlParameter[] param = new SqlParameter[14];
param[0] = new SqlParameter("@Username", SqlDbType.VarChar, 50);
param[1] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
param[2] = new SqlParameter("@ConfirmPassword", SqlDbType.VarChar, 50);
param[3] = new SqlParameter("@EmailID", SqlDbType.VarChar, 50);
param[4] = new SqlParameter("Firstname", SqlDbType.VarChar, 50);
param[5] = new SqlParameter("Lastname", SqlDbType.VarChar, 50);
param[6] = new SqlParameter("Address", SqlDbType.VarChar, 50);
param[7] = new SqlParameter("City", SqlDbType.VarChar, 50);
param[8] = new SqlParameter("State", SqlDbType.VarChar, 50);
param[9] = new SqlParameter("Country", SqlDbType.VarChar, 50);
param[10] = new SqlParameter("Postalcode", SqlDbType.Int, 100);
param[11] = new SqlParameter("PhoneNo", SqlDbType.Int,100);
param[12] = new SqlParameter("Gender", SqlDbType.Char, 10);
param[13] = new SqlParameter("DOB", SqlDbType.VarChar, 50);
param[0].Value = Username;
param[1].Value = Password;
param[2].Value = Confirmpassword;
param[3].Value = EmailID;
param[4].Value = Firstname;
param[5].Value = Lastname;
param[6].Value = Address;
param[7].Value = City;
param[8].Value = State;
param[9].Value = Country;
param[10].Value = Postalcode;
param[11].Value = PhoneNo;
param[12].Value = gender;
param[13].Value = DOB;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string msg = "Insert Error";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
public static void ClearControls(Control Parent)
{
if (Parent is TextBox)
{ (Parent as TextBox).Text = string.Empty; }
else
{
foreach (Control c in Parent.Controls)
ClearControls(c);
}
}
protected void Next1_Click(object sender, EventArgs e)
{
if (password.Text == confirmpass.Text)
{
ExecuteInsert(username.Text, password.Text, confirmpass.Text, EmailID.Text, firstname.Text, Lastname.Text, Address.Text, City.Text, State.Text, Country.Text,Postalcode.Text,Phoneno.Text,Gender.SelectedItem.Text,DOB.Text);
Response.Write("Record was successfully added");
ClearControls(Page);
}
else
{
Response.Write("password did not match");
password.Focus();
}
}