Go to Web Config and paste this
<connectionStrings>
<add name="constring" connectionString="data source=JAMES-PC\\SQLEXPRESS; initial catalog=staff; persist security info= true; integrated security= true" providerName="System.Data.SqlClient"/>
</connectionStrings>
and chane the code as follow
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);
con.Open();
string sql = @"DELETE FROM staff1 where name=@name;";
SqlCommand cmd = new SqlCommand("DELETE FROM staff1 where name=@name", con);
cmd.Parameters.AddWithValue("@name", 1); or
cmd.ExecuteNonQuery();
con.Close();
}
Always go with id for deletion.Thank You:-)