You're missing a "}" immediately before the
catch(SqlException ex)
to terminate the try block.
BTW: why do you have a block round the code immediately below
SqlCommand cmd=new SqlCommand("INSERT INTO persondetail VALUES (@name,@age,@salary)",conn);
Did you forget the
using
block start?
[edit]
Try this:
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text;
int age = Convert.ToInt32(textBox2.Text);
int salary = Convert.ToInt32(textBox3.Text);
try
{
string connectionstring = @"Data Source=THEONE\PARTH;Initial Catalog=testdatabase;Integrated Security=True;";
using (SqlConnection conn = new SqlConnection(connectionstring))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO persondetail VALUES (@name,@age,@salary)", conn))
{
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@age", age);
cmd.Parameters.AddWithValue("@salary", salary);
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
[/edit]