Try this.
From:
SqlCommand cmd;
cmd = new SqlCommand("Insert into student (id) values ("+ idTextBox.Text +")", cn);
Change to :
SqlCommand cmd = new SqlCommand("Insert into student (id) values ("+ idTextBox.Text +")", cn);
From
try
{
cn.Open();
cmd.ExecuteNonQuery;
resultLabel.Text = "added successfully";
}
Change to:
try
{
cmd.cn.Open();
cmd.ExecuteNonQuery;
resultLabel.Text = "added successfully";
}
Hope can help.