There are a lot of problems here!
The problem you have noticed is pretty simple: You are setting the connection string after you try to open the connection.
And please, don't do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead
Try this:
using (SqlConnection con = new SqlConnection(@"Data Source=GHARONDA-15; Initial Catalog=RagestrationDetail; Integrated Security=SSPI"))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO Form1 (Name, FatherName, Address, DateOfBirth, JoiningDate, Experience, EducationalQualification) VALUES (@NM, @FN, @AD, @DOB, @JD, @EX, @EQ)", con))
{
cmd.Parameters.AddWithValue("@NM", textBox1.Text);
cmd.Parameters.AddWithValue("@FN", textBox2.Text);
cmd.Parameters.AddWithValue("@AD", textBox3.Text);
cmd.Parameters.AddWithValue("@DOB", textBox4.Text);
cmd.Parameters.AddWithValue("@JD", textBox5.Text);
cmd.Parameters.AddWithValue("@EX", textBox6.Text);
cmd.Parameters.AddWithValue("@EQ", textBox7.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Saved");
}
}
But...You need to validate the dates are "real" dates, or SQL will throw an exception - and I'm hoping you are storing them as DATETIME values, or you will be giving yourself some really nasty problems in future.
And do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox4" is the date of birth today, but when you have to modify it is three weeks time, will you then? Use descriptive names - "tbBirthdate" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbBirthdate" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...