u have to check dr.HasRows in if, before update query
if(dr.HasRows)
{
String strQuery = "";
SqlConnection mySqlConnection = new SqlConnection(str);
strQuery += "update PersonalDetails set EnrolmentNo= ('CD' + ' " + dr["userid"].ToString() + " ') where userid = ' " + Convert.ToInt32(dr["userid"]) + " ' ";
SqlCommand com = new SqlCommand(strQuery, mySqlConnection);
mySqlConnection.Open();
com.ExecuteNonQuery();
mySqlConnection.Close();
con.Close();
}